Android – subtlety of Don’t keep activities

Android’s developer option “Don’t keep activities” is often recommended as a quick way to test application/activity behavior on process death/kill and restore by Android Framework. While this works, there is a subtle difference in Activity’s life cycle in real world scenario. In real world scenario, users background the app (ignoring PIP app) and the last focus activity is alive, paused, stopped but isn’t destroyed.

onCreate
onResume
onPause
onStop
onSaveInstanceState

However, in the case of using the developer option, the activity is actually destroyed immediately upon back grounding. This subtlety might or might not matter depending on how onDestroy’s logic in the activity but something to keep in mind while testing.

onCreate
onResume
onPause
onStop
onSaveInstanceState
onDestroy

And when this matters, the alternative is just not to use the developer option, instead kill from adb shell or use Android Studio’s process terminate option after back grounding the app.