A running application change it's state because of some interruptions
When a user presses the home button or when he gets a phone call or the app goes through a number of state transitions.
Before discussing the details about the topic,let's focus on the given flow chat of iOS App lifecycle.
iOS Interview Questions And Answers Part12
Top 5 Basic iOS Questions Asked in interviews
During the entire lifecycle of App,it moves through a series of states .Let me point out the several states of iOS Apps below.The iOS Application lifecycle shows each of the activity in an app from the time it is installed until the time it has been removed from a device.
Not running state- This state indicates the app is not launched yet or exited by the system.This means your app has either not been launched, or it has been terminated by the system for some reason.
The App currently staying in Not Running state can be moved into the inactive state when it's launched
Inactive state - This state indicates that the App is running but executing some other codes.This occurs while the app is in the foreground state but does not receive events
System locks Device screen automatically to save power.
The Apps that are currently inactive can move into either the active or background state.
Active state- It's also called running state .The app is running in the foreground and responding for users action. This is the normal mode for any running app.
Active apps can only transition into an inactive state.
Background state- This state indicates that the App is running in background and executing code. The app enetrs this state while working on any other app in foreground.This state indidates that the app is not active, but still executes code.
In this App state,the app can extend the execution time to run some additional stuffs.
Application's Background Transition Cycle in iOS
An app in the background state can move into either the inactive or suspended state.
The apps can only enter the background state on devices that support multitasking.
Concept Of Multitasking In iOS App
Suspended state- The app is running in background but not executing code.Apps in this state are in the background but they don't execute code or receive events.
-In this state ,system can suspend the App anytime without any notice,if it finds no tasks
to execute or tasks have been finished it's execution.
When the device goes through a low memory, system purges apps from memory to release memory.
This happens when an app is running in the foreground requires some additional resources.
Suspended apps can transition into the background or be terminated by the system as required
When an iOS Application moves from one state to another state, system triggers some events or methods,so that user can implement those events to accomplish some tasks.
Let's discuss those methods one by one.These methods are included in AppDelegate Class.AppDelegate is a Class centrally located to coordinate the behaviours of Application.
It's instantiated by the Main Class of iOS App.
This event is triggered when,the app is about to launch for the first time.It is the initial method of app delegate.
This event is triggered just after an app is launched first time.
This method is called just after an app enters in foreground mode. This says that app is in Active state.
This method is called just before an app enters in Background state. This Indicates that app is in Inactive state.
This method is called just after an app enters in Background state.
In this state app may move to suspended state at any time.
This event is called when an app state changes from background mode to foreground mode. It indicates that app is in Inactive state.
applicationWillTerminated : This method is called just before an app exits and try to transition into Not running state.