In order to persist state in my android app, so that the user will return to the activity they left off at, i've set the very useful flag alwaysRetainTaskState in my manifest:
<activity android:name=".Main"
android:label="@string/app_name"
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This gets the job done, or so I thought; I discovered that the system can still destroy my app's activities to preserve memory, while still keeping state. To verify this, I wrote a little test app that creates a whole bunch of activities in a loop to see if my app's activities would be destroyed. Sure enough, the system destroys my activities.
With some reading, I found that I need to use onSaveInstanceState() and onRestoreInstanceState() to help maintain activity state.
To get to my question, let's say I have an Activity with a number of global variables, some of them are static and some aren't. They consist of booleans, arraylists, strings, etc. My issue is that I am confused which of these variables are persistent when an activity is destroyed. Which ones should I package into the bundle in onSaveInstanceState()? Does the system do anything to these variables when an activity is destroyed?