- Open a bunch of tabs.
- Terminate the app by swiping it away from Android recents or an equivalent action.
- Relaunch the app.
- Observe that all tabs are gone! This is counter intuitive for users of many mobile browsers and apps and even for some desktop apps.
Researching this one made my head hurt. It looks like a lot of developers have confusion/complaints about this:
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...
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().