My app is running on a special device that is running a custom build of Android Gingerbread 2.3.7
There are conditions where the system will terminate my app. I assume that the device manufacturer considers these emergency situations where all third party apps should be immediately shut down so the device can do its primary tasks.
I can duplicate the behavior I see on the device using an emulator and in DDMS selecting my task and clicking the "Stop Process" button. Here is the behavior I see.
My app typically steps through four activities, Activity A launches activity B, B launches Activity C, and C launches activity D. So, when activity D is running on top, my stack is:
A - B - C - D
If at this point, the process is terminated, Activity D does not receive onPause() or an onStop() call. It has no opportunity to save its state.
After the process is dead, Android's ActivityManager starts a new task for my app and launches Activity C. I think this is standard Android behavior to restart crashed apps.
My question is can I control this restart behavior? If Android is going to restart my app, I need the activity stack restored, Activity C doesn't really make sense to be run stand alone (clicking the back button would exit the app and that doesn't make sense for this activity).
Can I prevent this restart? Can I have the restart start all my activities in sequence? Can I have the restart just start activity A?
I did find this interesting discussion which I believe explains why Activity C is restarted and not Activity D.
As far as when an activity is restarted -- if the process running the foreground activity goes away, the system will throw away that activity if it does not have a valid saved state for it (typically meaning it is paused and has given the system the result of onSaveInstanceState from before the pause). Once it has decided whether or not to throw away that activity, it will resume whatever activity is now at the top of the stack. If this is one of your activities -- either because you have another behind the one that crashed, or the one that crashed was somehow it the settled pause state -- then it will start your process again to show that top activity.
And some similar questions like Prevent Activity Stack from being Restored? and this interesting thread