The android activity lifecycle includes the following callbacks: onCreate()
, onStart()
, onResume()
, onPause()
, onStop()
, onRestart()
, and onDestroy()
.
onCreate()
The lifecycle of an android activity begins here. This is where any layout resources (Buttons, textViews, editText, etc.) and background threads are initialized.
onStart()
Called right after onCreate(). In this state the activity becomes visible to the user.
onRestart()
Called after an activity has been stopped. This call reverts the activity to its visible lifetime.
onResume()
Called when the user returns to an activity after briefly exiting it. The app stays in this state until something happens to take focus away from the app. Such an event might be, for instance, receiving a phone call, the user’s navigating to another activity, or the device screen’s turning off.
onPause()
Called when the user leaves the current activity to another activity or leaves the app for a while. It indicates that the activity is no longer in the foreground and certain processes that are not needed while the activity is not in the foreground will be stopped.
onStop()
Called when the activiy becomes invisible to the user. The activity and its resources may still be running in the background even though it is not visible. After onStop() is called, the activity will call onRestart() if it needs to be loaded again.
onDestroy()
The end of the activity lifecycle. This activity is used to stop all resources and tasks started in onCreate(). After onDestroy() is called, the activity will call onCreate() if it needs to be loaded again.
The system invokes this callback either because:
- The activity is finishing (due to the user completely dismissing the activity or due to finish() being called on the activity), or
- The system is temporarily destroying the activity due to a configuration change (such as device rotation or multi-window mode)
You can learn more about android life cycle here !
Top comments (3)
Thank you, if you use single activity and multiple fragments, you may need this picture (attached), I found it at web.
Thank you bro!
You are welcome bro!
If you want to learn android basic, you can also check this repo from github!
HeinKhantZaw / HuaweiAndroidTraining
Codes from Huawei Android Training
HuaweiAndroidTraining
Codes from Huawei Android Training
Getting Started
Download as zip file.
You can also clone by using git
Open Android Studio > File > Open
Choose a project from the folder.
Run the project!
For future sessions
As I'll be adding more example projects after future sessions, you can
git pull
or re-download the repo But I recommend to use git because you don't need to download again and again every time I upload new code You can learn more about git here!Here is the command of pulling the updated project.
This command pull the updated files and folder from the repo in github to your local repo in your laptop.
Details about each project
There's a README.md in every project. If you're interested, you can find more about the project in those README.md!
Day 1
Day 2