I am a working on an Android app and am a bit confused about the way the Activity stack specifically handles state information. I looked on the activity documentation about the matter and found this:
If an activity in the foreground of the screen (at the top of the stack), it is active or running.
If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.
If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.
I have an activity called SongList which is only initiated from one other activity and with the intent that initiates it, receives some state information. It also may move the user to a few other individual activities but each one has a back button that takes them back to SongList and is implemented with moveTaskToBack(true);
My question is how do I know what is happening with the state variables in SongList? Since none of the back buttons actually carry the state information, it seems if the user moves on to some of these other activities, when they hit back, it may either not take them back to SongList, or have lost all the state information and as such work improperly. Do I need to manually handle saving all this state information?
Can anyone point me in the right direction on resolving this issue, or perhaps just fill me in on anything that I might have missed in the documentation that addresses my concern.
Thanks in advance.
Avtar
Please allow normal BACK button processing (which does
finish(), notmoveTaskToBack()) to occur, unless you have a very good reason to do otherwise. Statistically speaking, it is unlikely that you have a very good reason to do otherwise.What “state variables in
SongList“?If you are referring to the
Intentextras for theIntentthat started this copy ofSongList, they should still be there, AFAIK.It is entirely possible that your messed-up BACK handling (see my opening paragraph) may be causing you difficulty. Normally,
Intentextras are not a problem with BACK button processing.If you have state that is beyond what is in those extras, you will need to use
onSaveInstanceState()andonRestoreInstanceState()to manage that, in case Android destroysSongListto free up memory and to handle configuration changes (screen rotations, being placed in a desk dock, etc.).