OSDN Git Service

Handle returning a result from automatic up navigation from another
authorAdam Powell <adamp@google.com>
Tue, 15 May 2012 23:51:55 +0000 (16:51 -0700)
committerAdam Powell <adamp@google.com>
Tue, 15 May 2012 23:53:34 +0000 (16:53 -0700)
task.

When navigating up from a different task, if the current activity has
a result set only finish the current activity instead of trying
finishAffinity. Log this so that developers know why this behavior is
happening.

Bug 6465336

Change-Id: Ic7cec6f0c0d5861296091e2aea9344309f5fc600

core/java/android/app/Activity.java

index ac55abe..69ee434 100644 (file)
@@ -2713,7 +2713,16 @@ public class Activity extends ContextThemeWrapper
                 onCreateNavigateUpTaskStack(b);
                 onPrepareNavigateUpTaskStack(b);
                 b.startActivities();
-                finishAffinity();
+
+                // We can't finishAffinity if we have a result.
+                // Fall back and simply finish the current activity instead.
+                if (mResultCode != RESULT_CANCELED || mResultData != null) {
+                    // Tell the developer what's going on to avoid hair-pulling.
+                    Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result");
+                    finish();
+                } else {
+                    finishAffinity();
+                }
             } else {
                 navigateUpTo(upIntent);
             }