Android Tutorial Graphical Life Cycle of a B4A Activity

Hi all...

I'm posting this in the hopes that it'll help anyone programming with B4A to understand the life cycle of an activity. I struggled with this a bit, and the graphical representation made it easier for me to understand. I hope it helps some of you. (Thanks to Erel for proofing it for me!) Cheers...

alc.png
 
Last edited:

Shadow&Max

Active Member
Licensed User
Longtime User
Thanks tds...
 

stevel05

Expert
Licensed User
Longtime User
Nice one, a picture speaks a thousand words.
 

Shadow&Max

Active Member
Licensed User
Longtime User
Thank you both... changes have been made and are reflected in newly uploaded image...
 

Shadow&Max

Active Member
Licensed User
Longtime User
Done...
 

udg

Expert
Licensed User
Longtime User
Hello,

I found this valuable resource only today thanks to a post by corwin42.
Correct me if I am wrong; when an app is terminated (back key pressed, last activity executing its activity.finish, so cases 3&4 in diagram), next starting point is depended on whether or not the garbage collector cleaned up the app's memory, destroying its process.
I mean, if GC wholly reclamed your app's process memory, it is my understanding that next starting point will be Process_Globals (and FirstTime again True when it comes to activity create).

udg
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not exactly. You are confusing Garbage Collection which is an inner-process feature with the process management of the OS.

The app (process) is not terminated when the last activity is destroyed.
The process is terminated when:
1. The app is in the background and there are no foreground services.
2. The OS needs the memory for other processes.

If the process was terminated then FirstTime will be true when the app is "resumed".
 

udg

Expert
Licensed User
Longtime User
Thank you Erel.
I didn't know GC was part of the process/app! As you spotted, I saw it as part of the OS.
Anyway, shouldn't the diagram take in account the possibility that the OS claims back process memory when the app is terminated by 3&4 above?

One last question (promised): back key and activity.finish take the app in background where it stays until launched again, awaked by a service or destroyed by the OS. What does ExitApplication differently from activity.finish? Does it force the OS to recover process memory not waiting for a low-mem condition?

udg
 

thedesolatesoul

Expert
Licensed User
Longtime User
Anyway, shouldn't the diagram take in account the possibility that the OS claims back process memory when the app is terminated by 3&4 above?
It wont happen at 3&4. It will happen outside the scope of this chart i.e. when the OS/user is doing something else.
 
  • Like
Reactions: udg

Erel

B4X founder
Staff member
Licensed User
Longtime User
What does ExitApplication differently from activity.finish
ExitApplication terminates the process. In most cases you should avoid using it and let the OS manage the processes.

One of the problems with calling ExitApplication is that the OS treats the process as if it has crashed. In some cases it will try to restart previously running services.
 
Top