Restoring state in Android when using the 'up' button
android, android-activity, android-lifecycle
Solution
Try setting the main activity's launch mode to singleTop, in your manifest:
<activity android:name="activityName" android:launchMode="singleTop" ... />
Problem
I am using `onSaveInstanceState()` to store an `ArrayList` member variable and restore it in the `onCreate()` method of the main activity. This works in most circumstances such as rotating the screen etc. but if I open a new activity and use the 'up' button (not the back button) to navigate back to the main screen it seems to create a new main activity without passing the state bundle in `onCreate()`. I have confirmed that when the up button is pressed the `onDestroy()` method is called for the original instance of the main activity which makes no sense to me because I want it to resume the existing activity as if I had pressed the back button rather than create a new one. Is there a way I can force the new activity to restore the old one or just resume the existing activity?