Activity and Fragment life cycle

Ported from Android Developer

 

Activity

 

Managing the Activity Lifecycle

 

As you'll learn in the following lessons, there are several situations in which an activity transitions between different states that are illustrated in figure 1. However, only three of these states can be static. That is, the activity can exist in one of only three states for an extended period of time:

Resumed
In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the "running" state.)
Paused
In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code.
Stopped
In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.

The other states (Created and Started) are transient and the system quickly moves from them to the next state by calling the next lifecycle callback method. That is, after the system calls onCreate(), it quickly calls onStart(), which is quickly followed by onResume().

That's it for the basic activity lifecycle. 

 

 

 

 

Activities

 

 

About the difference between onStop and onPause causing the state

Difference between onPause and onStop

Simply put, after the activity is paused, it may only be partially blocked, and other places are visible, or the activity above is transparent, but cannot interact with the user; but it is completely invisible after stopping.

 

 

Fragment

 

Building a Dynamic UI with Fragments

 

Fragments



 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327034461&siteId=291194637