iOS Application Lifecycle

Vikas Pandey
2 min readAug 16, 2019

--

Understanding of Application Lifecycle is very important to iOS developers. You should take full advantage of application states to make your application intuitive and user-friendly.

Every iOS application will go through following states :

1. Not running
2. Inactive
3. Active
4. Background
5. Suspended

Let’s look deep into these states …

Not running : Either the application is not started or is terminated by system.

Inactive : An application is running in the foreground but is not receiving any events. User interaction is not possible at this time. This happens when a call or SMS is received.

Active : An application is running in the foreground and receiving the events. User interaction happens only in this state.

Background : An application is running in the background and executing the code.

Suspended : An application is in the background but is not executing the code. In case of low memory, iOS may purge suspended application without notice to make free space for the currently running application.

iOS calls specific methods within the application delegate to facilitate transitioning to and from various states.

application:willFinishLaunchingWithOptions
This method is called after your application has been launched successfully. This is the first opportunity to execute any code within the app. You should do any required initial setup for application.

application:didFinishLaunchingWithOptions
This method called when the launch process is going to complete but before your app’s window and other UI is presented.

applicationDidBecomeActive
This method is called when the app is moved from inactive to active state. You should use this method to restart any tasks that were paused or not started yet while the application was inactive.

applicationWillResignActive
This method is called when the application is about to become inactive, e.g. A phone call or user presses home button. You should use this method to pause any ongoing tasks.

applicationDidEnterBackground
This method is called when an app is running, but no longer in the foreground means user interface is not currently being displayed.
You have approximately 5 seconds to perform any tasks and return back. If you need additional time, you can request from the system by calling beginBackgroundTask(expirationHandler:).

applicationWillEnterForeground
This method is called when an app is preparing to move from the background to the foreground.

applicationWillTerminate
This method is called when your application is about to be purged from the memory. When user quit the app, shutting down the device or any crash triggers the applicationWillTerminate.
You should save the application configuration, settings, core data save, user preferences and final cleanup.

Thanks for reading …

--

--