Bug 1305439 - Store the last selected tab in GeckoApp in onPause and switch back to it in onResume. r=sebastian
☠☠ backed out by 20754fd4499a ☠ ☠
authorDylan Roeh <droeh@mozilla.com>
Thu, 13 Oct 2016 12:49:44 -0500
changeset 317826 46db039dbe102cf4529df8fe237b20455c3f154d
parent 317825 67300cfca7338c03a71e713f1b7103367fad4b29
child 317827 9126be480c4594a25352ce6e585fb8b6afe5ef6f
push id82759
push userdroeh@mozilla.com
push dateThu, 13 Oct 2016 17:52:24 +0000
treeherdermozilla-inbound@46db039dbe10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1305439
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1305439 - Store the last selected tab in GeckoApp in onPause and switch back to it in onResume. r=sebastian
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -155,16 +155,17 @@ public abstract class GeckoApp
     public static final String PREFS_ALLOW_STATE_BUNDLE    = "allowStateBundle";
     public static final String PREFS_VERSION_CODE          = "versionCode";
     public static final String PREFS_WAS_STOPPED           = "wasStopped";
     public static final String PREFS_CRASHED_COUNT         = "crashedCount";
     public static final String PREFS_CLEANUP_TEMP_FILES    = "cleanupTempFiles";
 
     public static final String SAVED_STATE_IN_BACKGROUND   = "inBackground";
     public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession";
+    public static final String SAVED_STATE_LAST_TAB        = "lastTab";
 
     // Delay before running one-time "cleanup" tasks that may be needed
     // after a version upgrade.
     private static final int CLEANUP_DEFERRAL_SECONDS = 15;
 
     private static boolean sAlreadyLoaded;
 
     protected RelativeLayout mRootLayout;
@@ -197,16 +198,18 @@ public abstract class GeckoApp
     private final HashMap<String, PowerManager.WakeLock> mWakeLocks = new HashMap<String, PowerManager.WakeLock>();
 
     protected boolean mLastSessionCrashed;
     protected boolean mShouldRestore;
     private boolean mSessionRestoreParsingFinished = false;
 
     private EventDispatcher eventDispatcher;
 
+    private Tab lastSelectedTab = null;
+
     private static final class LastSessionParser extends SessionParser {
         private JSONArray tabs;
         private JSONObject windowObject;
         private boolean isExternalURL;
 
         private boolean selectNextTab;
         private boolean tabsWereSkipped;
         private boolean tabsWereProcessed;
@@ -578,16 +581,25 @@ public abstract class GeckoApp
     }
 
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
 
         outState.putBoolean(SAVED_STATE_IN_BACKGROUND, isApplicationInBackground());
         outState.putString(SAVED_STATE_PRIVATE_SESSION, mPrivateBrowsingSession);
+        outState.putInt(SAVED_STATE_LAST_TAB, lastSelectedTab.getId());
+    }
+
+    @Override
+    protected void onRestoreInstanceState(final Bundle state) {
+        super.onRestoreInstanceState(state);
+
+        final int tabId = state.getInt(SAVED_STATE_LAST_TAB);
+        Tabs.getInstance().selectTab(tabId);
     }
 
     public void addTab() { }
 
     public void addPrivateTab() { }
 
     public void showNormalTabs() { }
 
@@ -2075,16 +2087,20 @@ public abstract class GeckoApp
         // Undo whatever we did in onPause.
         super.onResume();
         if (mIsAbortingAppLaunch) {
             return;
         }
 
         GeckoAppShell.setGeckoInterface(this);
 
+        if (lastSelectedTab != null) {
+            Tabs.getInstance().selectTab(lastSelectedTab.getId());
+        }
+
         int newOrientation = getResources().getConfiguration().orientation;
         if (GeckoScreenOrientation.getInstance().update(newOrientation)) {
             refreshChrome();
         }
 
         if (mAppStateListeners != null) {
             for (GeckoAppShell.AppStateListener listener : mAppStateListeners) {
                 listener.onResume();
@@ -2149,16 +2165,18 @@ public abstract class GeckoApp
     @Override
     public void onPause()
     {
         if (mIsAbortingAppLaunch) {
             super.onPause();
             return;
         }
 
+        lastSelectedTab = Tabs.getInstance().getSelectedTab();
+
         final HealthRecorder rec = mHealthRecorder;
         final Context context = this;
 
         // In some way it's sad that Android will trigger StrictMode warnings
         // here as the whole point is to save to disk while the activity is not
         // interacting with the user.
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override