Lesson 3. Application Lifecycle

This lesson explains the lifecycle of some components of an application. When developing an application is important to be aware of the interaction that the final user will have with it. Different events have an specific result in the application behavior, things like closing the application or losing the internet connection

Activity Type Lesson
Expected Duration 30 minutes
Topic Application Lifecycle
Objective • Comprehend the human-device relationship and the behavior of the application as a result of this relation.
• Implement some services for each state of the lifecycle of iOS.
• Learn to use some graphical components like load dialogs.

1. Lifecycle of an application

There are shared resources in the mobile devices like the battery and the memory RAM. That means that multiple processes in the device are constantly using those resources, and someone or something has to be in charge of managing them. when using a device with iOS, the OS in the one that is releasing (ending) processes that are not in use or to creating processes when needed. So, as developers we should be aware when are the processes of our app are in a state in which the OS is capable of releasing them.

The different stages and the changes between them of the components/processes/views of our application is called the lifecycle. The lifecycle of an iOS application can be represented in a general level with the following diagram:

Lifecycle Diagram 1: iOS lifecycle. Image from: https://developer.apple.com

The states of the lifecycle are:

States Lifecycle Table 1: States of iOS lifecycle. Image from: https://developer.apple.com

In iOS the applications go to the Background state immediately after they leave the screen. But even if they stay only a short time in this state before they are suspended, there is a possibility that the application will continue to execute code in this state for much longer. For instance Waze, or Skype. Those kind of applications need special permissions to not be suspended by the system when they are in background state. In iOS there is a class called AppDelegate, that is in charge of implementing the methods that are launched when a change of state occurs or when other types of important changes happen, like notifications. The methods of the state changes are:

In each of this methods you can implement a lot of functionalities and actions. For instance, delete resources that the application will not need anymore when it goes to the background state, or created resources when the application comes back from the background state.

2. Lifecycle of a controller (ViewController)

We talked about the applications lifecycle, but the controllers have also one, with its respective states. The states are similar to the application ones and let the developer know when the view has been shown and when is not. The states are:

Controller Lifecycle Diagram 2: transitions of state of a view controller. Image from: https://developer.apple.com

Like the AppDelegate methods, the controller allows you to implement methods when the state changes happens. The following list contains the methods in execution order:

  1. (void)loadView
  2. (void)viewDidLoad
  3. (void)viewWillAppear
  4. (void)viewWillLayoutSubviews
  5. (void)viewDidLayoutSubviews
  6. (void)viewDidAppear
  7. (void)viewWillDissapear
  8. (void)viewDidDissapear

Version Author Date
1.0 Juan David Cruz Serrano February 20, 2017
1.1 Mario Linares February 21, 2017
1.2 Juan David Cruz Serrano February 21, 2017
2.0 Sergio Velasquez February 28, 2018

results matching ""

    No results matching ""