Android Question Life of Main Activity and Secondary Activities

Guardian17

Active Member
Licensed User
Longtime User
I think I know the answer to this, but I haven't been able to find anything on the B4A site to confirm it.

Let's say I have a Main Activity, and I start a second Activity, Activity2. Also, Activity2 relies on the state of a Boolean (from the Main Activity) in its Activity_Create Sub.

My question is, is there ever a situation in the Activities Cycle where Main will be destroyed but Activity2 will remain alive in memory and could be re-started on its own due to an orientation change, such that that Boolean no longer exists? Or does the Android OS know that Activity2 is associated with the Main Activity, such that if Main is destroyed, Activity2 will also be destroyed?
 

Guardian17

Active Member
Licensed User
Longtime User
In that case Activity_Create of the main activity will not be called.
In light of this, does each Activity have its own separate StateManager file, or is there a single StateManager file used commonly by all Activities in a Project? Assuming a common single file, I am interested in knowing whether Activity2, started in the Main Activity using StartActivity, can use values in the common StateManager file that the Main Activity saved using StateManager.SaveSettings, (as opposed to using a Process_Global in the Main Activity, which may not currently exist if the process was re-started from Activity2).

Stated another way, can any Activity in a Process use ANY saved Setting saved by any of the other Activities?

Also, does the StateManager file remain persistent in the device if the process is stopped, (i.e. a Setting saved today can still be recalled one year from now), or does the StateManager file get destroyed at some point?
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Process global variables are not tied to any specific activity or service. They are tied to the process.

However it is possible that the process will be killed and later recreated and started directly from the second activity. In that case Activity_Create of the main activity will not be called.


Then you should initialize those "kind of variables" when you declare them, despite the IDE gives a warning, or not?
Usually you declare the variable and set its first value in Activity_Create, but as you wrote... !
 
Upvote 0
Top