Other What is automatically preserved and what is lost on an Activity Pause \ Resume?

Gary Milne

Active Member
Licensed User
Longtime User
I've read the thread "Android Process and activities life cycle" as well as the relevant portion of the book but they do not address the issue of object initialization and best practices for dealing with the Pause\Resume cycle.

Which things are guaranteed to persist in a Pause\Resume cycle?
  1. Process Globals in other previously run Activity? i.e. top level "Activity Main".
  2. Process Globals: Variables defined in Process Globals in this current Activity? i.e. Activity "Activity Sub"
  3. Globals: Variables defined in globals and their values. Do they need to be re-initialized and values reassigned.
  4. Loaded layouts - should they be reloaded on Resume?
  5. Views added by variables located in Globals?
  6. I know user state data does not persist.
Any information gratefully received.
 

klaus

Expert
Licensed User
Longtime User
1. persist
2. persist
3. persist
4. no
5. persist

In general:
- Process_Global variables persist as long as the process runs, no matter where they are defined.
- Layouts should be defined in Activity_Create, loaded from a file and / or defined in code.
 
Upvote 0

Gary Milne

Active Member
Licensed User
Longtime User
With respect to numbers #4 and #5 it appears that they do NOT persist and have to be reloaded in Activity_Create\Resume otherwise the app Resumes to a blank screen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Which things are guaranteed to persist in a Pause\Resume cycle?
You asked about the Pause\Resume cycle.
4. Loaded layouts - should they be reloaded on Resume?
The answer is NO.
5. Views added by variables located in Globals?
In the Pause\Resume cycle they are persistant.

If you change the screen orientation the cycle is Pause > Create > Resume then the layouts will be recreated in Activity_Create.
 
Upvote 0

Gary Milne

Active Member
Licensed User
Longtime User
I think it is semantics as I'm sure you know the answers. But for the other newbies out there I wish to clarify the answers to the questions I posed.
1. Persist - variables and there values persist until the main thread is exited
2. Persist - variables and there values persist until the main thread is exited
3. No - these must be reloaded\recreated in Activity_Create or Activity_Resume
4. Yes - layouts must be reloaded in Activity_Create or Activity_Resume
5. No - These must be recreated in Activity_Create or Activity_Resume
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
3) 4) 5) layouts must be reloaded\recreated in Activity_Create not in Activity_Resume.
You may need to update contents of views in Activity_Resume but not reload\recreate the layouts.
 
Last edited:
Upvote 0
Top