[JAVA] Activity life cycle
Overview u> h2>
Understanding and coding the Activity lifecycle methods is very important.
The general role of each method is described below.
Call order th> | Method name th> | Role th> tr>
|
1 td> | onCreate td> | Perform initial processing before the screen is visualized td> tr>
|
2 td> | onStart td> | Perform the processing just before the screen is visualized td> tr>
|
3 td> | onResume td> | Process the screen visualization state td> tr>
|
4 td> | onPause td> | Perform processing when the screen transitions to another screen td> tr>
|
5 td> | onStop td> | Perform processing when the screen disappears td> tr>
|
6 td> | onDestroy td> | Perform the process just before the screen is destroyed td> tr>
|
Details u> h2>
oncreate
- Initializes resources that should be initialized only once when an activity is created. li>
- 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. li>
onStart
- Called just before showing Activity to the user li>
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 (). li>
onResume
- Called when Activity returns or when a new intent arrives li>
- 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. li>
onPause
- Called when Android tries to transition to another Activity. li>
- Preparation to stop interacting with the user. li>
onStop
- Called when Activity is invisible to the user li>
- The above can happen when an activity is destroyed or hidden by another activity li>
- Cancel the monitoring of background processing that changes the UI, etc. set in the onStart () method. li>
onDestroy
- Called just before Activity is destroyed. li>
It is common to release the resources acquired by
- onCreate. li>