I know how to handle "Don't keep activities" option in App. I can use onSaveInstanceState
and onRestoreInstanceState
, etc.
In this question, I want to know how the Android Framework handles the option. eg.
- When user switches the App to the background, we know the current Activity will be destroyed. But I don't know how the Framework to do this. I can't find the process in Framework. I need your help to provide some clues of the process in source code.
- If only one Activity in you App, and you switch the App to the background, is the
ActivityStack
destroyed?When you switch the app from background to foreground, will theActivityStack
be recreated? Can you provide some source code.
Thank you for your reading. Maybe you can write something. ^_^
I don't have the source code handy, so can't be sure, but I assume that it works as if you would set
android:noHistory="true"
on all activities.The answer to your second question is that the single
Activity
would be destroyed, leaving theActivityStack
empty. When the user returns to the app, a new instance of theActivity
would be created and initialized with the previously saved state of theActivity
. The OS process may or may not be destroyed and recreated in this case, it depends how long the app was left in the background and how aggressive the implementation of the Android framework is (this behaviour is different, depending on device manufacturer and on the amount of resources the device has).