Page MenuHomePhabricator

[Spike 5 hours] App state is lost when closing it from Recent Apps list.
Closed, ResolvedPublic

Description

  1. Open a bunch of tabs.
  2. Terminate the app by swiping it away from Android recents or an equivalent action.
  3. Relaunch the app.
  4. Observe that all tabs are gone! This is counter intuitive for users of many mobile browsers and apps and even for some desktop apps.

Event Timeline

Niedzielski raised the priority of this task from to Needs Triage.
Niedzielski updated the task description. (Show Details)
Niedzielski updated the task description. (Show Details)
Niedzielski set Security to None.
Dbrant triaged this task as High priority.Jun 26 2015, 2:11 PM
Dbrant added a subscriber: Dbrant.

It looks like it doesn't save our instanceState when the app is terminated this way. We would need to dump the tab state to a file, and read it on next launch...

Researching this one made my head hurt. It looks like a lot of developers have confusion/complaints about this:
http://android.stackexchange.com/questions/19987/what-actually-happens-when-you-swipe-an-app-out-of-the-recent-apps-list
http://www.reddit.com/r/Android/comments/mpevh/id_like_to_squash_this_growing_misconception/c32s7wv
http://stackoverflow.com/questions/31329615/preserve-activity-state-after-swiping-it-from-recent-app-list

Anyway, it looks like the Activity's savedInstanceState doesn't get preserved when it's swiped away from the Recent Apps list. So, one possible solution would be to store our state in SharedPreferences (or at least some of our state) when onSaveInstanceState is called, and then restore the state from SharedPreferences the next time the activity is launched...

@Dbrant, thanks for the links. A frustratingly complex experience in an Android lifecycle.

Dbrant renamed this task from All tabs are lost upon app termination to App state is lost when closing it from Recent Apps list..Jul 10 2015, 6:10 PM
MBinder_WMF renamed this task from App state is lost when closing it from Recent Apps list. to [Spike 5 hours] App state is lost when closing it from Recent Apps list..Jul 15 2015, 5:34 PM
Dbrant removed Dbrant as the assignee of this task.Jul 16 2015, 4:16 PM

I built a quick test app to prove the lifecycle and can confirm empirically that Bundle is not preserved when intentionally killed by the user. We need to manually save state.

My recommendation is to build something based off the AOSP Browser sources. I also looked at Chromium but the additional platforms supported makes the codebase more complex and I believe some of the state saving is implemented in C++.

Browser uses Bundles everywhere but at the last moment call Bundle.writeToParcel() and use Parcel.marshall() to write to a file. The most relevant sources are src/com/android/browser/CrashRecoveryHandler.java, src/com/android/browser/Controller.java, src/com/android/browser/BrowserActivity.java, and src/com/android/browser/BrowserSettings.java. Note: Controller.onSaveInstanceState() is called from both BrowserActivity.onSaveInstanceState() and onSaveInstanceState.onNewIntent().

Dbrant closed this task as Resolved.Jul 21 2015, 12:05 PM