It's a life cycle that I often hear when developing Andorid, but if you don't know what it is, you may not know what implementation should be implemented in which method, or you may make a mistake, so I would like to summarize it.
The image above is a life cycle diagram.
Activity provides a screen that the user can do. Describes the view display and actions when the button is clicked.
The state of an activity changes until it is created and destroyed, and this change is the life cycle. The onCreate () and onStart () etc. shown in the image are called callback methods and are used as overrides in the code we implement. Looking at the source code, I think that onCreate () and onStart () exist.
onCreate This is the process that is performed when the screen is displayed. The screen will be initialized. Set which screen to display.
When the onCreate process is complete, onStart () is called.
The source code performs the following processing.
setContentView(R.layout.activity_task_edit)
onStart Called when the Activity is started. At this point, the activity has been generated but is invisible to the user.
In onStart (), describe the start of reading data. If you don't need to read the data, I think you should implement it.
onResume Called just before the Activity comes to the fore and can start interacting with the user. You will be able to use the screen.
onPause Called when another app comes to the fore and the Activity hides in the background. It is used to commit data changes and to stop other operations that may consume CPU.
It is followed by onResume () when the Activity is brought back to the front, and followed by onStop () when the Activity is hidden.
onStop Called when the screen disappears from the user. It is called when you return to the home screen, change the screen, or the app disappears.
onDestroy Called just before the Activity is destroyed. You can terminate the DB connection here.
onRestart Called when the Activity comes back after onStop (). For example, it is used when the device goes to sleep and starts again, or when you press the home button on the device to restart the running app.
This time it was a rough outline, but if you have any concerns, I would like to describe it after organizing your thoughts.
Android Developers -- https://developer.android.com/guide/components/activities?hl=ja
(The life cycle diagram is on the above site)
Recommended Posts