Confusion between background and paused applications

I am a little confused in these two states. The following is my understanding;

when the application is in the background and if you have "Application does not run in background" set to NO in the pl pl file of the application, the application continues to run in the background. In pause mode, the application remains in memory, but do not execute the code! The system does not notify the application when it transitions to a paused state and erases the application from memory in low memory conditions to create space for applications in the foreground.

Do I understand correctly? If so, why am I not getting my NSLog printed on the console when the application is running in the background and executing code? What actually happens with my TCP socket connection, where I constantly get data from the server? Why do we need a suspended state, one way or another, the system eventually wipes the application from memory in a low memory situation. Is there a difference between the fact that the application becomes active from a suspended state or starting a new one?

+5
source share
3 answers

Refer to the "Applications and Application Multitasking" section of the IOS Application Programming Guide. Find this by searching the Xcode documentation with the phrase “Application Status and Multitasking” and “Hits Must” set to “Match Search Term.” Another useful search phrase: "Background execution."

The consolidated answer is that the application can continue to "execute" in the background an unlimited number of times for a limited number of reasons:

in iOS, only certain types of applications are allowed to run in the background:

  • Applications that play audio content for the user in the background, for example, an application for a music player.
  • Applications that inform users of their location at any time, such as a navigation application
  • Voice over Internet Protocol (VoIP) Applications
  • Press applications to download and process new content.
  • Applications regularly receiving updates from external accessories

In addition to these specific operations, the application may ask you to continue execution for a very short time, which is contained in the documentation for the section "Performing a task of finite length in the background." After a short time, your application will inform the system that it is done (and then suspended), or it is forcibly terminated. Details in the document.

Another useful bit of this document with good state diagrams is the "Managing Application State Changes" section. This section talks about becoming a thing of the past and coming back to the fore. He should answer your question about the difference between the starting light and the beginning from a paused state. The short (not entirely correct) answer is that if you start with a paused state and do not take any special actions when entering the background or (re) entering the foreground, you simply continue more or less from where you were, In addition, starting from a paused state is faster. Read the document as it says it is much better than my paraphrase.

+2
source

Application status

Not running: your application is in this state until it starts.

Active: as soon as your application is running, receiving events.

Inactive: when your application is running, but something interrupts it, for example, a phone call, it becomes inactive. Inactive means that the application is still running in the foreground but not receiving events.

Reason: in this state, your application is no longer in the foreground, but it can still run code.

Suspended Your application goes into this state when it can no longer run code.

+2
source

Background:

  • Code execution - code is executed when the application is in the background.
  • An application must transition to a background state before it can transition to a suspended state.
  • i.e. Suppose you are on Facebook, upload a video and quickly switch to another application immediately after you press the POST button. Although you switched to another application without terminating it, it can be configured to run background processes to complete the download.
  • An application that is in the background does not necessarily mean that it is suspended, but an application that is suspended is in the background.
  • An application may request to be in the background for additional time (for example, to play sound in the background or to perform a network request); after that, it will either go into a suspended state, or will be forcibly terminated by the system.

Subpring:

  • Code is not executed - code is not executed while the application is in a suspended state.
  • An application that is in a paused state is also in the background.
  • The system puts applications in this state without prior notice.
  • The application in suspended state is still in memory.

Some additional information that may help you in this topic:

-6
source

All Articles