Close ad

There are still a lot of people who don't know how multitasking works in iOS. To begin with, however, it is necessary to point out that this is not real multitasking, but a very smart solution that does not burden the system or the user.

One can often hear superstitions that apps running in the background in iOS fill up the operating memory, which leads to system slowdown and battery life, so the user should turn them off manually. The multitasking bar does not actually contain a list of all running background processes, but only the most recently launched applications. So the user doesn't have to worry about processes running in the background except in a few cases. When you press the Home button, the application usually goes to sleep or closes, so that it no longer loads the processor or the battery and, if necessary, frees up the necessary memory.

So this is not full-fledged multitasking when you have dozens of processes running. Only one application is always running in the foreground, which is paused or turned off completely if necessary. Only a few secondary processes run in the background. That's why you will rarely encounter an application crash on iOS, for example Android is overwhelmed with running applications that the user has to take care of. On the one hand, this makes working with the device unpleasant, and on the other hand, it causes, for example, slow startup and transitions between applications.

Application runtime type

The application on your iOS device is in one of these 5 states:

  • Running: the application is started and running in the foreground
  • Background: it is still running but running in the background (we can use other applications)
  • Suspended: Still using RAM but not running
  • Inactive: the application is running but indirect commands (for example, when you lock the device with the application running)
  • Not running: The application has terminated or has not started

The confusion comes when the app goes into the background so as not to disturb. When you press the Home button or use the gesture to close the application (iPad), the application goes into the background. Most apps are suspended within seconds (They are stored in the iDevice's RAM so they can be launched quickly, they don't load the processor as much and thus save battery life) You might think that if an app continues to use memory, you have to manually delete it to free it up . But you don't have to do that, because iOS will do it for you. If you have a demanding application suspended in the background, such as a game that uses a large amount of RAM, iOS will automatically remove it from memory when necessary, and you can restart it by tapping the application icon.

None of these states are reflected in the multitasking bar, the panel only shows a list of recently launched apps regardless of whether the app is stopped, paused, or running in the background. You may also notice that the application that is currently running does not appear in the Multitasking panel

Background tasks

Normally, when you press the Home button, the application will run in the background, and if you are not using it, it will automatically pause within five seconds. So if you're downloading a podcast, for example, the system evaluates it as a running application and delays the termination by ten minutes. After ten minutes at the latest, the process is released from memory. In short, you don't have to worry about interrupting your download by pressing the Home Button, if it doesn't take more than 10 minutes to complete it.

Indefinite running in the background

In the case of inactivity, the system terminates the application within five seconds, and in the case of downloads, termination is delayed for ten minutes. However, there are a small number of applications that require running in the background. Here are some examples of apps that can run in the background indefinitely in iOS 5:

  • Applications that play sound and must be interrupted for a while (pausing music during a phone call, etc.),
  • Applications that track your location (navigation software),
  • Applications receiving VoIP calls, for example if you use Skype, you can receive a call even when the application is in the background,
  • Automatic downloads (eg Newsstand).

All applications should be closed if they are no longer performing a task (such as background downloads). However, there are exceptions that run in the background continuously, such as the native Mail app. If they are running in the background, they take up memory, CPU usage or reduce battery life

Apps that are allowed to run in the background indefinitely can do anything they do while they're running, from playing music to downloading new Podcast episodes.

As I mentioned before, the user never needs to close the apps running in the background. The only exception to this is when an app running in the background crashes or doesn't wake up from sleep properly. The user can then close the applications manually in the multitasking bar, but this rarely happens.

So, in general, you don't need to manage background processes because the system will take care of them itself. That's why iOS is such a fresh and fast system.

From a developer's perspective

The application can react with a total of six different states as part of multitasking:

1. applicationWillResignActive

In translation, this state means that the application will resign as the active application (that is, the application in the foreground) in the future (a matter of a few milliseconds). This happens, for example, when receiving a call while using the application, but at the same time, this method also causes this state before the application goes into the background, so you need to take these changes into account. This method is also suitable so that, for example, it suspends all the activities it is performing when there is an incoming call and waits until the end of the call.

2. applicationDidEnterBackground

The status indicates that the application has gone into the background. Developers should use this method to suspend all processes that don't necessarily need to run in the background and clear memory of unused data and other processes, such as expiring timers, clearing loaded images from memory that won't necessarily be needed, or closing connections with servers, unless it is critical for the application to complete connections in the background. When the method is invoked in an application, it should essentially be used to completely suspend the application if some part of it is not required to run in the background.

3. applicationWillEnterForeground

This state is the opposite of the first state, where the application will resign to the active state. The state simply means that the sleeping app will resume from the background and appear in the foreground within the next few milliseconds. developers should use this method to resume any processes that were inactive while the application was in the background. Connections to servers should be reestablished, timers reset, images and data loaded into memory, and other necessary processes can resume just before the user sees the loaded application again.

4. applicationDidBecomeActive

The state indicates that the application has just become active after being restored to the foreground. This is a method that can be used to make additional adjustments to the user interface or to restore the UI to its original state, etc. This actually happens at the moment when the user already sees the application on the display, so it is necessary to determine with caution what happens in the method of this and in the previous method. They are called one after the other with a difference of a few milliseconds.

5. applicationWillTerminate

This state happens a few milliseconds before the application exits, that is, before the application actually terminates. Either manually from multitasking or when turning off the device. The method should be used to save processed data, to end all activities and to delete data that will no longer be needed.

6. applicationDidReceiveMemoryWarning

It is the last state that is the most discussed. It is responsible for, if necessary, removing the application from iOS memory if it uses system resources unnecessarily. I don't know specifically what iOS does with background apps, but if it needs an app to release resources to other processes, it prompts it with a memory warning to release whatever resources it has. So this method is called in the application. Developers should implement it so that the application gives up the memory it has allocated, saves everything in progress, clears unnecessary data from memory, and otherwise adequately frees memory. It's true that many developers, even beginners, don't think about or understand such things, and then it can happen that their application threatens battery life and/or unnecessarily consumes system resources, even in the background.

Verdict

These six states and their associated methods are the background of all "multitasking" in iOS. it's a great system, as long as developers don't ignore the fact that there is a need to be responsible about what the application throws up on their users' devices, if they are minimized or get warnings from the system and so on.

Source: macworld.com

Authors: Jakub Požárek, Martin Doubek (ArnieX)

 
Do you also have a problem to solve? Do you need advice or perhaps find the right application? Do not hesitate to contact us via the form in the section Counseling, next time we will answer your question.

.