iOS App States; All you need to know
In iOS, there are five app states. While the OS manages the app state, the critical tasks are controlled by the app itself to ensure smooth state changes.
The five iOS apps states are as follows:
Not Running:
The app has neither been started by the user nor the system, nor has it already been terminated.
There is no code to handle this state as the app is not running.
Inactive:
Although it is active in the foreground, the app is not getting any events. This state only lasts a moment before the app switches to another state.
An example of this:
The application briefly enters an inactive state before switching to the background when a call is received. In this situation, the app is active in the foreground, but it is not getting events.
You can handle it simply in your App Delegate:
Active:
The app is running in the foreground and receiving events, such as the user clicking a button or inputting some text.
You can handle it simply in your App Delegate:
Background:
The app is still running, but it’s in the background, and it does not receive user input.
An example of this:
Suppose a user starts downloading files or content in your app and decides to switch to another app. In this state, the app can continue executing code and downloading the files.
This Method can be used very handy when you need to cleanup tasks, save data or stop timers.
We got another method we can use in background state before the app continues to move to Foreground.
Suspended
The application is still running in memory while being suspended. The system enters this state when it has to make room for other apps.
An example of this:
The app switches to the suspended state if the user hasn’t used it for a long and the system has to free up memory. The application still runs in this mode, but no code is being executed.
We got two practical methods in App Delegate to handle the memory warning received from the system, and the app is about to be terminated.
I appreciate you choosing to spend some of your day with me. I hope that my piece was informative and helpful to you.
Farewell, keep growing and learning and see you in the next one. ✌️
Make sure to follow me on Twitter to keep receiving the newest articles: