diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index 788d4b9bce..78df80fb32 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -54,14 +54,12 @@ import java.util.ArrayList; public class Folder extends LinearLayout implements DragSource, View.OnClickListener, View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener { - protected DragController mDragController; - - protected Launcher mLauncher; - - protected FolderInfo mInfo; - private static final String TAG = "Launcher.Folder"; + protected DragController mDragController; + protected Launcher mLauncher; + protected FolderInfo mInfo; + static final int STATE_NONE = -1; static final int STATE_SMALL = 0; static final int STATE_ANIMATING = 1; @@ -132,6 +130,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList if (sHintText == null) { sHintText = res.getString(R.string.folder_hint_text); } + + mLauncher = (Launcher) context; } @Override @@ -286,10 +286,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mDragController = dragController; } - void setLauncher(Launcher launcher) { - mLauncher = launcher; - } - void setFolderIcon(FolderIcon icon) { mFolderIcon = icon; } diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java index 283c2954f6..952916d5f9 100644 --- a/src/com/android/launcher2/FolderIcon.java +++ b/src/com/android/launcher2/FolderIcon.java @@ -127,7 +127,6 @@ public class FolderIcon extends LinearLayout implements FolderListener { Folder folder = Folder.fromXml(launcher); folder.setDragController(launcher.getDragController()); - folder.setLauncher(launcher); folder.setFolderIcon(icon); folder.bind(folderInfo); icon.mFolder = folder; diff --git a/src/com/android/launcher2/FolderInfo.java b/src/com/android/launcher2/FolderInfo.java index b5b5b29c19..3ae31d2781 100644 --- a/src/com/android/launcher2/FolderInfo.java +++ b/src/com/android/launcher2/FolderInfo.java @@ -99,6 +99,12 @@ class FolderInfo extends ItemInfo { } } + @Override + void unbind() { + super.unbind(); + listeners.clear(); + } + interface FolderListener { public void onAdd(ShortcutInfo item); public void onRemove(ShortcutInfo item); diff --git a/src/com/android/launcher2/ItemInfo.java b/src/com/android/launcher2/ItemInfo.java index 3a1c29a45e..8d46624955 100644 --- a/src/com/android/launcher2/ItemInfo.java +++ b/src/com/android/launcher2/ItemInfo.java @@ -144,7 +144,13 @@ class ItemInfo { values.put(LauncherSettings.Favorites.ICON, data); } } - + + /** + * It is very important that sub-classes implement this if they contain any references + * to the activity (anything in the view hierarchy etc.). If not, leaks can result since + * ItemInfo objects persist across rotation and can hence leak by holding stale references + * to the old view hierarchy / activity. + */ void unbind() { } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 33a86a95b9..5e500ba76f 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -221,8 +221,6 @@ public final class Launcher extends Activity private static LocaleConfiguration sLocaleConfiguration = null; - private ArrayList mDesktopItems = new ArrayList(); - private static HashMap sFolders = new HashMap(); // Hotseats (quick-launch icons next to AllApps) @@ -1098,8 +1096,6 @@ public final class Launcher extends Activity screen, cellXY[0], cellXY[1], false); if (!mRestoring) { - mDesktopItems.add(launcherInfo); - // Perform actual inflation because we're live launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); @@ -1228,7 +1224,6 @@ public final class Launcher extends Activity } public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { - mDesktopItems.remove(launcherInfo); removeWidgetToAutoAdvance(launcherInfo.hostView); launcherInfo.hostView = null; } @@ -1359,7 +1354,7 @@ public final class Launcher extends Activity TextKeyListener.getInstance().release(); - unbindDesktopItems(); + unbindWorkspaceItems(); getContentResolver().unregisterContentObserver(mWidgetObserver); unregisterReceiver(mCloseSystemDialogsReceiver); @@ -1743,11 +1738,8 @@ public final class Launcher extends Activity * Go through the and disconnect any of the callbacks in the drawables and the views or we * leak the previous Home screen on orientation change. */ - private void unbindDesktopItems() { - for (ItemInfo item: mDesktopItems) { - item.unbind(); - } - mDesktopItems.clear(); + private void unbindWorkspaceItems() { + LauncherModel.unbindWorkspaceItems(); } /** @@ -3016,9 +3008,8 @@ public final class Launcher extends Activity }); } - // This wasn't being called before which resulted in a leak of AppWidgetHostViews (through - // mDesktopItems -> AppWidgetInfo -> hostView). - unbindDesktopItems(); + // This wasn't being called before which resulted in a leak of AppWidgetHostViews + unbindWorkspaceItems(); } /** @@ -3034,7 +3025,6 @@ public final class Launcher extends Activity for (int i=start; i