YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Active and Visible Lifetimes - Developing Android Apps

Get Embed Code
10 Languages

Showing Revision 14 created 05/24/2016 by Udacity Robot.

  1. The active life cycle is when your activity is in the foreground and
  2. has focus. Here it is actively receiving input from user events and
  3. no other activities are obscuring it. On [UNKNOWN] and
  4. the active lifetime ends as soon as your activity is partially obscured,
  5. like in this example. [SOUND] You can see here the permissions dialogue
  6. is displayed in front of Google Play for
  7. an app in store. Or the same thing happens when you have another activity trying
  8. to fulfill an implicit intent and the user needs to make a selection. So
  9. to make efficient use of limited resources,
  10. you'll want to use these signals to adjust your app's resource burden.
  11. So, most updates through a UI, can be paused when this lifetime ends,
  12. which is announced by onPause. But as you see, the app is still visible, so
  13. you shouldn't pause any processes that are drawing your UI. The visible
  14. lifetime on the other hand continues whenever the app is at all visible and
  15. ends as soon as it's completely obscured by another app. Like this.
  16. [SOUND] At this point, our app is moved to the background.
  17. So when you see on stop, you know the user can't see your app at all. So, while
  18. OnCreate and OnDestroy will be called at most once, each time your app is run,
  19. these handlers are likely to be called many times, while the app is running.
  20. Now, this is where things get a little different. On almost al platforms,
  21. app life cycles are deterministic. Generally, you'll start a program and
  22. it'll keep running, until it either completes or the user cancels it. You look
  23. at traditional desktop development that means your app keeps running until your
  24. user chooses quit or exit from the file menu. At that point you can say stay and
  25. free resources. But as we know on Android life cycles work a little differently.
  26. So, let's take a closer look at exactly how that works now.