iOS Tutorial Application life cycle

The life cycle of iOS applications is quite simple.

The two most important events are Application_Start and Application_Background.

The standard way to start an application is by clicking on its icon.
This will cause Application_Start to run. Application_Start only runs once when the process starts.
It is always the first sub to run.
You will usually load the layout in this sub and optionally restore the state.
Note that at this point the actual page size is not known.

The process will continue running until the user closes the application. This happens when the user presses on the home button.

Application_Background will be called when the application is moving to the background. This is the place to save the user data and also to save the state. You should assume that the process will be killed shortly after this sub.

Normal applications do not run in the background. There are no services in iOS.

Application_Active will be raised when the app is active. Which means that the user can interact with it. It will follow Application_Start and Application_Foreground events.

Application_Inactive will be raised when the app is still in the foreground but the user cannot interact with it. It will be raised before Application_Background. It can also be raised when there is an interruption such as a phone call. In this case Application_Inactive will be raised and if the user doesn't answer the call Application_Active will be raised.

Application_Foreground will be called after the app transitions from the background to the foreground. This event will only fire if the process was not killed while the app was in the background.

The last event is Application_OpenUrl. This event is fired when another app sends a URL to the system that your app is registered to. This is another way to start applications. This is how for example B4i-Bridge launches the apps during debugging.
 

tuhatinhvn

Active Member
Licensed User
Longtime User
Normal applications do not run in the background. There are no services in iOS.
I saw some app can play music when i press home button?
How do they do? can we make with B4I?
 

tufanv

Expert
Licensed User
Longtime User
how do we end an application
like in b4a : activity.finish or exitapplication
 

tufanv

Expert
Licensed User
Longtime User
no i just want to end applciation when the user clicks exit button ?
There are ways to kill an app however Apple will not accept your app to the app store if you use those APIs.
 

tufanv

Expert
Licensed User
Longtime User
Application_Background will be called when the application is moving to the background. This is the place to save the user data and also to save the state. You should assume that the process will be killed shortly after this sub.

Normal applications do not run in the background. There are no services in iOS.


I forgot to implement to check the subscription status in one of my apps on application_foreground. It only checks at appication_start

is this means that my app will always use app_foreground sub until user double clicks on home and closes app OR as you wrote above the process is killed shortly after app_background and for example 3 hours later when it is opened again it will use app_start instead of app_foreground ?

ty
 

tufanv

Expert
Licensed User
Longtime User
You do not need to check it in application_foreground. The process will be killed a few minutes after the app is in the background. A new process always starts from Application_Start.
Erel,

I leave the app in background for 1-2 hours and when i click on the app icon again , it starts from where i left the app. It does not execute anything from the applicaiton_start
 

JonPM

Well-Known Member
Licensed User
Longtime User
Erel,

I leave the app in background for 1-2 hours and when i click on the app icon again , it starts from where i left the app. It does not execute anything from the applicaiton_start

I think what Erel was trying to say is that it isn't necessary to check subscription status every time your so app is brought to the foreground. Just check it once on app start like you are already doing, that is sufficient.
 
Top