Lifecycle phases – what we need to know

The Android system has multiple different phases that any given app can be in. Depending upon the phase, the Android system determines how the app is viewed by the user or whether it is viewed at all. Android has these phases, so it can decide which app is in current use and then allocate the right amount of resources, such as memory and processing power. But it also allows us as app developers to interact with these phases.

We have already raised the issue of what will happen if the user quits our app to answer a phone call, will they lose their progress/data/important note?

Android has a fairly complex system that, when simplified a little for the purposes of explanation, means that every app on an Android device is in one of the following phases:

  • Being created
  • Starting
  • Resuming
  • Running
  • Pausing
  • Stopping
  • Being destroyed

The list of phases will hopefully appear fairly logical. As an example, the user presses the Facebook app icon and the app is created. Then it is started. All fairly straightforward so far, but next in the list is resuming. It is not as illogical as it might first appear. If, for a moment, we can just accept that the app resumes after it starts, then all will become clear as we proceed.

After resuming, the app is running. This is when the Facebook app has control of the screen and probably the greater share of system memory and processing power. Now, what about our example when we switched from the Facebook app to the e-mail app?

As we tap to go to read our e-mail, the Facebook app will probably have entered the paused phase, followed by stopping, and the e-mail app will enter the being created phase, followed by resuming, then running. If we decide to revisit Facebook, as in the scenario earlier, the Facebook app will probably skip being created, then it will restart, resume, and be running again, most likely exactly on the post we left it on.

Note that, at any time, Android can decide to stop, then destroy an app. In which case, when we run the app again, it will need to be created at the first phase all over again. So, had the Facebook app been inactive long enough, or had Angry Birds required so many system resources that Android had destroyed the Facebook app, then our experience of finding the exact post we were previously reading might have been different.

If all this phase stuff is starting to get confusing then you will be pleased to know that the only reason to mention it is so that:

  • You know it exists
  • We occasionally need to interact with it
  • We will take things step by step when we do
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.121.131