[JAVA] Activity life cycle

Overview Understanding and coding the Activity lifecycle methods is very important. The general role of each method is described below.
Call order Method name Role
1 onCreate Perform initial processing before the screen is visualized
2 onStart Perform the processing just before the screen is visualized
3 onResume Process the screen visualization state
4 onPause Perform processing when the screen transitions to another screen
5 onStop Perform processing when the screen disappears
6 onDestroy Perform the process just before the screen is destroyed

Details

oncreate

  • Initializes resources that should be initialized only once when an activity is created.
  • When it is destroyed and recreated by rotation etc., if the previous state is saved, the Bundle object which is the argument of onCreate () is passed.

onStart

  • Called just before showing Activity to the user Since the period from when
  • onStart () is called to when onStop () is called is the period during which the screen is displayed to the user, the callback for background processing is registered here. For example, register a broadcast receiver in the onStart () method to monitor for notifications that cause changes that affect the UI, and unregister it with onStop ().

onResume

  • Called when Activity returns or when a new intent arrives
  • Activity is in the foreground, doing heavy processing just before interacting with the user If you pinch it, it will be displayed and you will not be able to operate it for a while, so It is recommended to make the process called here as light as possible.

onPause

  • Called when Android tries to transition to another Activity.
  • Preparation to stop interacting with the user.

onStop

  • Called when Activity is invisible to the user
  • The above can happen when an activity is destroyed or hidden by another activity
  • Cancel the monitoring of background processing that changes the UI, etc. set in the onStart () method.

onDestroy

  • Called just before Activity is destroyed. It is common to release the resources acquired by
  • onCreate.