- Android Wear Projects
- Ashok Kumar S
- 376字
- 2021-07-15 17:17:56
Lifecycle of an Android activity
Each screen on Android applications has a lifecycle. When you open any application, some sort of screen will welcome you. In the background, this launched screen must be created before it can convey its content to your eyes. Without you even realizing, the screen or activity experienced a couple of stages in its lifecycle. We'll discuss what lifecycle implies in Android programming.
During its lifetime, an Android activity will be in one of the following states:
- Running
- Paused
- Stopped
- Killed
The lifecycle callback methods are as follows:
- onCreate()
- onStart()
- onResume()
- onPause()
- onStop()
- onDestroy()
- onRestart()
The following diagram explains the lifecycle of an activity:

- onCreate(): Basically, this event gets fired just once when the activity is started. This is a good place to initialize any information, such as, variables' lists view components and so on.
- onStart(): Once the activity enters the “started” state, the activity becomes visible and interactive.
In this method, the Android system maintains all the code that are related to the user interface and business logic of the application. - onResume(): This event is called whenever the user returns to the activity after leaving from the activity — such as receiving a call, pressing the home button, turning off the screen, or transitioning to another activity.
- onPause(): The activity calls this method as the first indication that the user is leaving your activity and this method sets all the process to be idle.
- onStop(): Using this callback activity is no longer visible to the user because either a new activity gets started or the existing activity gets the resumed state. The next callback that the system calls is either onRestart() to bring the activity back to interact with the user, or onDestroy() to terminate the activity.
- onDestroy(): This method is called before the activity is destroyed. This is the final call that the activity receives. Using this method, we can unregister the hardware, such as accelerometer, microphone, and so on. We can terminate all the file writing operations in this method.
Now, without waiting any further, let's get started on creating packages and start coding.
推薦閱讀
- 嵌入式軟件系統(tǒng)測(cè)試:基于形式化方法的自動(dòng)化測(cè)試解決方案
- Rake Task Management Essentials
- Visual FoxPro 程序設(shè)計(jì)
- 精通軟件性能測(cè)試與LoadRunner實(shí)戰(zhàn)(第2版)
- 好好學(xué)Java:從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- C# Multithreaded and Parallel Programming
- PHP 7從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- 代替VBA!用Python輕松實(shí)現(xiàn)Excel編程
- 深入實(shí)踐Kotlin元編程
- RubyMotion iOS Develoment Essentials
- Django Design Patterns and Best Practices
- Mastering JavaScript
- Python Machine Learning Cookbook
- C# 7.0本質(zhì)論
- 測(cè)試工程師Python開(kāi)發(fā)實(shí)戰(zhàn)