Android Question Use Cases for running Process_Globals etc

PhilipBrown

Active Member
Licensed User
Longtime User
I'm trying to get a complete list of which Subs are automatically run under different circumstances.
This might have already been done but I can't find it.
So far my list is as follows.
Have I got it right, and have I missed any use-cases?

This list contains errors and omissions. See later posts for better lists.

When the user first launches your app or brings it to the front after quitting
(Quitting could be by pressing the Back button or your app calling Activity.Finish.
If the user has previously run your app and the Process has not yet been killed, it will be re-used. Otherwise a new Process is created.)
Process_Globals is run.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.

When the user runs another app
Activity_Paused is run with the UserClosed parameter set to False.
(Android will determine when the Process ends.
If the user brings your app to the front before the Process is killed, Process_Globals will not be run.)

When the user clicks the Back button
Activity_Paused is run with the UserClosed parameter set to True.
(Android will determine when the Process ends.
The next time the app is run, Process_Globals will be run.)

When the user brings your app to front after running a different app
Globals is run.
Activity_Create is run with FirstTime parameter set to False.
Activity_Resume is run.

When the user rotates the device
Sub Activity_Paused is run with the UserClosed parameter set to False.
The screen takes on its new configuration.
Globals is run.
Activity_Create is run with FirstTime parameter set to False.
Activity_Resume is run.

When your app calls Activity.Finish
(You might have an Exit button which calls this.)
Activity_Paused is run with the UserClosed parameter set to True.
Android will determine when the Process ends.
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Upvote 0

PhilipBrown

Active Member
Licensed User
Longtime User
The previous list contained errors and omissions.
Here is the latest list.

When the user first launches your app or brings it to the front after quitting
(Quitting could be by pressing the Back button or your app calling Activity.Finish.
If the user has previously run your app and the Process has not yet been killed, it will be re-used. Otherwise a new Process is created.)
Process_Globals is run in all activities.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.

When the user runs another app
Activity_Paused is run with the UserClosed parameter set to False.
(Android will determine when the Process ends. See Process.
If the user brings your app to the front before the Process is killed, Process_Globals will not be run.)

When the user clicks the Back button
Activity_Paused is run with the UserClosed parameter set to True.
(Android will determine when the Process ends. See Process.
The next time the app is run, Process_Globals will be run.)

When the user brings your app to front after running a different app
(If Android has not killed your app’s Process)
Globals is run.
Activity_Resume is run.
(If Android has killed your app’s Process)
Process_Globals is run.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.

When the user rotates the device
Activity_Paused is run with the UserClosed parameter set to False.
The screen takes on its new configuration.
Globals is run.
Activity_Create is run with FirstTime parameter set to False.
Activity_Resume is run.

When your app calls Activity.Finish
(You might have an Exit button which calls this.)
Activity_Paused is run with the UserClosed parameter set to True.
Android will determine when the Process ends. See Process.

When one activity opens another using StartActivity
First activity runs Activity_Paused with the UserClosed parameter set to False.
Second activity runs Process_Globals is run.
Second activity runs Globals.
Second activity runs Activity_Create with FirstTime parameter set to True.
Second activity runs Activity_Resume.

When second activity closes and first activity resumes
(For example if second activity calls Activity.Finish)
Second activity calls Pause with UserClosed set to True.
First activity runs Resume.
 
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
In my Post#9 in this thread: https://www.b4x.com/android/forum/t...and-object-initializations.55287/#post-350256

I believe I proved that Activity_Pause in the Main Activity does not occur until the END of the SUB in which StartActivity is used.

So this part of your list:
When one activity opens another using StartActivity
First activity runs Activity_Paused with the UserClosed parameter set to False.

can be changed to:

When one activity opens another using StartActivity
the First Activity sub in which StartActivity is used is run to completion.
First activity runs Activity_Paused with the UserClosed parameter set to False.
....


Later in that same thread, I posted the following to distinguish using Activity.Finish versus StartActivity(Main) to "exit" the Second Activity:
 
Last edited:
Upvote 0

PhilipBrown

Active Member
Licensed User
Longtime User
Thanks Guardian17. I've revised the use cases below and added some new ones.

You say

I have further learned that you can use Activity.Finish to exit the second Activity, which will allow you to fully exit the Activity in which it is used.
In fact, Android remembers that you have already entered the second activity, so the next time you enter it, FirstTime will be False.

the Activity in which you may use StartActivity(Main) may remain in memory in a Paused State
I'm not sure why you would want to do this, since the history traced by the Back button would then be First Activity, Second Activity, First Activity. Wouldn't this be a little confusing for the user?

Here's the revised list of use cases.

When the user first launches your app or brings it to the front after quitting
(Quitting could be by pressing the Back button or your app calling Activity.Finish.)
- If the user has not previously run your app, or if she has and the Process has been killed:
A new Process is created.
Process_Globals is run in all activities.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.
- If the user has previously run your app and the Process has not yet been killed:
Process_Globals is run in all activities.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.

When the user runs another app
Activity_Pause is run with the UserClosed parameter set to False.
(Android will determine when the Process ends.)

When the screen is turned off
Activity_Pause is run with the UserClosed parameter set to False.

When the screen is turned back on
Activity_Resume is run.

When the user clicks the Back button
Activity_Pause is run with the UserClosed parameter set to True.
(Android will determine when the Process ends.
The next time the app is run, Process_Globals will be run.)

When the user brings your app to front after running a different app
- If Android has not killed your app’s Process:
Globals is run.
Activity_Resume is run.
- If Android has killed your app’s Process:
Process_Globals is run.
Globals is run.
Activity_Create is run with FirstTime parameter set to True.
Activity_Resume is run.

When the user rotates the device
Activity_Pause is run with the UserClosed parameter set to False.
The screen takes on its new configuration.
Globals is run.
Activity_Create is run with FirstTime parameter set to False.
Activity_Resume is run.

When your app calls Activity.Finish
(You might have an Exit button which calls this.)
Activity_Pause is run with the UserClosed parameter set to True.
Android will determine when the Process ends.

When one activity opens another using StartActivity
First activity calls StartActivity(SecondActivity)
Sub in first activity finishes running.
First Activity calls Activity_Pause with the UserClosed parameter set to False.
Second activity runs Process_Globals.
Second activity runs Globals.
Second activity runsActivity_Create.
(FirstTime parameter is either True or False depending whether second activity has run before.)
Second activity runsActivity_Resume.

When second activity closes and first activity resumes
(For example if second activity calls Activity.Finish)
Second activity calls Pause with UserClosed set to True.
First activity runs Resume.
 
Last edited:
Upvote 0

Gunther

Active Member
Licensed User
Longtime User
Your 'see Process' are dead links since they are pointing to a local Harddisk :
B4X:
https://www.b4x.com/android/forum/file:///G:/SkyDrive/PennySystems/Android/Basic4Android/Book/B4A5.docx#Process
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…