OSDN Git Service

Don't let old Launcher activity interfere with new one
authorAdam Cohen <adamcohen@google.com>
Tue, 30 Sep 2014 16:48:49 +0000 (09:48 -0700)
committerAdam Cohen <adamcohen@google.com>
Tue, 30 Sep 2014 17:23:18 +0000 (10:23 -0700)
-> Launcher uses a static instance of it's loader (across
   multiple activities) since activities can come and go
   (configuration change, eg.) but the data model and loading
   is static.
-> Currently, this is not robust to a sequence of events that
   looks like onCreate(instance A), onCreate(instance B),
   onDestroy(instance B) -- depending on the timing of those
   calls.
-> This CL addresses a symptom of the above scenario by not
   allowing an older Launcher Activity cancel the loader /
   clear the callbacks for a newer Activity.

Bug 17679693

Change-Id: I8ece93e288464b0d578b9669c165b67132d997ed

src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherModel.java

index 37a7f5c..6780812 100644 (file)
@@ -1134,7 +1134,9 @@ public class Launcher extends Activity
     @Override
     public Object onRetainNonConfigurationInstance() {
         // Flag the loader to stop early before switching
-        mModel.stopLoader();
+        if (mModel.isCurrentCallbacks(this)) {
+            mModel.stopLoader();
+        }
         if (mAppsCustomizeContent != null) {
             mAppsCustomizeContent.surrender();
         }
@@ -1997,8 +1999,13 @@ public class Launcher extends Activity
 
         // Stop callbacks from LauncherModel
         LauncherAppState app = (LauncherAppState.getInstance());
-        mModel.stopLoader();
-        app.setLauncher(null);
+
+        // It's possible to receive onDestroy after a new Launcher activity has
+        // been created. In this case, don't interfere with the new Launcher.
+        if (mModel.isCurrentCallbacks(this)) {
+            mModel.stopLoader();
+            app.setLauncher(null);
+        }
 
         try {
             mAppWidgetHost.stopListening();
index dd94891..60eb15f 100644 (file)
@@ -1385,6 +1385,10 @@ public class LauncherModel extends BroadcastReceiver
         return isLaunching;
     }
 
+    public boolean isCurrentCallbacks(Callbacks callbacks) {
+        return (mCallbacks != null && mCallbacks.get() == callbacks);
+    }
+
     public void startLoader(boolean isLaunching, int synchronousBindPage) {
         startLoader(isLaunching, synchronousBindPage, LOADER_FLAG_NONE);
     }