How does Android Framework process the option of 'don't keep activities'?

86 Views Asked by At

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.

  1. 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.
  2. 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 the ActivityStack be recreated? Can you provide some source code.

Thank you for your reading. Maybe you can write something. ^_^

1

There are 1 best solutions below

4
On

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 the ActivityStack empty. When the user returns to the app, a new instance of the Activity would be created and initialized with the previously saved state of the Activity. 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).