The activity life cycle

onCreate

The activity is being created and does some initialization here

onRestart

Actvity is being restarted, normally as a result of user action

onStart

The activity is being started, the activity is visible, but it is still in the background and cannot interact

onResume

The activity is visible and in the foreground, where it can interact

onPause

OnStop is called immediately when the activity is stopping, and onResume is called in special cases when the activity is quickly restarted

onStop

The activity is about to stop, so you can do part of the reclaiming without being too time-consuming

onDestory

The activity is about to be destroyed, where it is recycled and freed

Life cycle switching process

The figure below, from the Android website, shows the life-cycle switching process

It can be divided into the following situations:

  1. The first activity to start :onCreate->onStart->onResume;

  2. Start a new activity on the current activity:onPause->onStop. If the new activity has a transparent theme, the current activity does not call onStop.

  3. User returns to the original activity:onRestart->onStart->onResume;

  4. When the user clicks back :onPause->onStop->onDestory;

  5. OnPause ->onStop->onDestory->onCreate->onStart->onResume The system also calls onSveInstanceState (called before onStop) to save some state of the current activity, and calls onRestoreInstanceState (called after onStart) to retrieve those saved in onSveInstanceState Data;