Note the basic program unit Activity:

In the android application, four basic components are provided, namely Activity, Service, BroadcastReceiver and ContentProvider. Activity is one of the most common components in android applications. In android, Activity represents a screen in a mobile phone or tablet. It provides a visual interface for interacting with the user. In an activity, you can add many components.
In an android application, there can be multiple activities. These activities form the Activity stack. The current activity is at the top of the stack. The previous activity is Push it below, become an inactive Activity, and wait for whether it is possible to be restored to an active
state.In the life cycle of an Activity, there are 4 important states:

The current operating status of the Activity, Activity top of the stack is located, visible to the user, and can get the focus
suspend state loses focus of Activity, still visible, but in low memory conditions, the system can not be killed (killing)
is stopped by other state in the Activity It is covered by Activity and is not visible, but it still saves all the state and information. When the memory is low, it will be
destroyed by the system . The activity ends, or the virtualizer process where the activity is located ends.

Callback methods in the activity life cycle:

onCreate() is called back when the Activity is created. This method is the most common method. When creating an Android project in Android Studio, an Activity is automatically created. In this Activity, the onCreate(Bundle savedInstanceState) method is overridden by default. It
is called back when the Activity is initialized onStart() when the Activity is started, that is, when an Activity becomes visible, it is called back
onResume() When the Activity is restored from the suspended state to the active state, after calling this method, the Activity is located in the Activity At the top of the stack, this method is always
called back when the onPause() is executed after the onPause() method . This method needs to be executed very quickly, because the next Activity can not be resumed until the method is executed. In this method, it is usually used to persist data. For example, when a phone call comes suddenly while playing a game, then the game state can be persisted in this method.
OnRestart() is called back when the Activity is restarted. This method always After the onStart() method is executed,
onStop() is called back when the Activity is stopped
onDestory() is called back when the Activity is destroyed

In Activity, you can rewrite the corresponding methods according to the needs of the program. Normally, the onCreate() and onPause() methods are the most commonly used, and these two methods are often rewritten.

Guess you like

Origin blog.csdn.net/qq_42823109/article/details/94360521