From the course: Android Development Essential Training: 3 Navigation

Explore the activity lifecycle - Android Tutorial

From the course: Android Development Essential Training: 3 Navigation

Start my 1-month free trial

Explore the activity lifecycle

- [Instructor] An activity is a single focus thing that the user can do. It typically represents a single screen in your application. For example, if you have a banking app the first screen that the user sees may be an account overview, that would be one activity. Then when they click on a specific account, they're taken to the list of recent transactions. That would be another activity. Each activity has its own life cycle. An activity has essentially four states. Active or running. This stage usually the activity that the user is currently interacting with. Visible. It's lost focus but still presented to the user. For example, maybe a transparent screen is being displayed on top. Stopped or hidden. This means it's no longer visible to the user. And then destroyed. The system has dropped the activity from memory. As a user navigates through an in and out of your app, the activity instances in your app transition through the different states in their life cycle. The activity class provides a number of callbacks that allow it to know that a state has changed. That way, you as the developer can declare how your activity should behave. There is a core set of six callbacks. OnCreate. Called only once when the activity is first created. This is where perhaps you will perform some setup. OnStart. The activity is now invisible but it's not yet in the foreground. OnResume, the activity is now in the foreground and the user can interact with it. OnPause, the activity is no longer in the foreground so the user may no longer be interacting with it. OnStop, the activity is no longer visible. And then finally onDestroy. This is called before the activity is destroyed. Now the system invokes each of these callbacks as an activity enters a new state. I know this may seem like a lot when you're just getting started with Android development, but don't worry, we'll be working with the activity life cycle throughout the remainder of the course. Also I'll share how Jetpack components make handling these changes a brief.

Contents