About the Android life cycle

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.

無題.png

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.

reference

Android Developers -- https://developer.android.com/guide/components/activities?hl=ja

(The life cycle diagram is on the above site)

Recommended Posts

About the Android life cycle
About the basics of Android development
About the method
Activity life cycle
About the package
Output about the method # 2
About the StringBuilder class
About Android basic grammar
Commentary: About the interface
About the asset pipeline
About the ternary operator
Summarize the life cycle of Java objects to be aware of in Android development
About the Kernel module
About the authenticate method.
About the map method
About the ancestors method
[Output] About the database
About the [ruby] operator
About the to_s method.
About Android App Components
I examined the life cycle of the extension of JUnit Jupiter
About the handling of Null
About specifying the JAXRS path
About truncation by the number of bytes of String on Android
Output about the method Part 1
about the where method (rails)
A note about the scope
About the description of Docker-compose.yml
Activity life cycle
About Bean and DI
About the Android life cycle
[Java] Spring DI ④ --Life cycle management
About the explanation about functional type
Android Spot the Difference Game
About the programming language Crystal
Consideration about the times method
10 Things I Hate About Android
[Android / Java] Learned about DataBinding
About the behavior of ruby Hash # ==
About the language to be learned
[Rails] About the Punk List function
About the equals () and hashcode () methods
About the symbol <%%> in Rails erb
[Android] Get the date on Monday
About the information sharing app band
About the current development environment (Java 8)
A murmur about the utility class
About the role of the initialize method
[Java] Spring DI ④ --Life cycle management
Think about the 7 rules of Optional
Summary about the introduction of Device
About the log level of java.util.logging.Logger