Description of Activity Lifecycle - Created

The book says this for the Created activity lifecycle stage:

“Created represents an activity that has an instance in memory but whose view is not visible on the screen. This state occurs in passing when the activity is first spinning up and reoccurs any time the view is fully out of view (such as when the user launches another full-screen activity to the foreground, navigates to the Home screen, or uses the overview screen to switch tasks).”

So this state also occurs when the view has disappeared? That’s counter-intiuitive, and I can’t find any supporting documentation for this online. I just want to confirm this is correct. It doesn’t make sense that onCreate (i.e. going back into the Created state) would get called again when the user is in the activity, then decides to switch to another app or go to the home screen. It’s almost the opposite of creating the activity - you’re leaving it.

I think you are conflating two subtly distinct concepts here: lifecycle states and lifecycle events.

An Activity always has one (and only one) lifecycle state. For example, when an Activity is fully visible and interactable to a user, it is in the “resumed” state. After an Activity is launched and put into the background by the user, it is in the “created” state.

Lifecycle events occur as an Activity transitions between lifecycle states. For example, there is a lifecyle event that occurs when your Activity transitions between the “nonexistent” state and the “created” state. You can perform some work (like setting up your UI) in your Activity when that lifecycle event happens by overriding the onCreate() function. The Android OS will invoke that function for you when that particular lifecycle event occurs.

I hope this explanation helps.

Small nitpick: onCreate() only gets invoked once for an individual Activity because, for a single Activity, it will only move from the “nonexistent” state to the “created” state once. The Activity could move from the “created” state to the “started” state multiple times (for example if you put the Activity in the background and then pull it back up many times), and each time that happened, the onStart() lifecycle event would be invoked.

I recommend that you continue working through the rest of Chapter 3. It will give you more hands-on experience with these topics. If you still have more questions at the end of the chapter, I am very happy to answer them.

Thanks for your response on this. I think this makes more sense, particularly after getting through the chapter. My understanding is that these states are distinct from the lifecycle methods that are called. In other words, when the app is put in the background, it’s in the Created state (since there is no Stopped or Paused state, even though onPause and onStop would get called in this case).