Activity Lifecycle in Android in full detail

Sudish Kumar
2 min readFeb 5, 2021

It is very necessary to understand the activity life cycle in Android. When we will understand it will be easy to handle it. When we understood it , it’s help us for handle functions and Another things like, when we have to store data in database a, update and delete methods we can also do and more things can be done.

What is life cycle

It’s a journey of born to death. Like we all know that a child will born after that he or she will become in childhood then he will become in Adolescence or kisora awastha after that he will become in Yong generation after that he will be old and lastly he will dead💀 .

Let’s understand it’s methods

There is seven months of activity life cycle. onCreate(), onStart (),onResume (), onPause(), onStop(), onDistoy() and onRestart()

onCreate ()

It’s mean activity is creating. Or being ready for starting. It’s called at first of fall after that another methods will be called when we open a Activity .

onStart()

It mean our activity is starting or in starting mode .

onResume()

When user is interacting with ui or user can see the ui and it’s data .

onPause()

On pause called when we exist from clicking by home button. When we exist by the home button our app runs in background when we left it for few minutes then or killed by itself.

onStop()

It’s mean activity is stopped. After onPause it’s called.

onDestoy()

it’s mean activity is killed. It called when we exist from back button.

onRestart()

It’s mean activity is restarting.

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Toast.makeText(this, "activity is creating", Toast.LENGTH_SHORT).show()

}

override fun onStart() {
super.onStart()

Toast.makeText(this, "Activity is starting", Toast.LENGTH_SHORT).show()

}

override fun onResume() {
super.onResume()

Toast.makeText(this, "Activity is resuming", Toast.LENGTH_SHORT).show()
}

override fun onPause() {
super.onPause()

Toast.makeText(this, "Activity is paused", Toast.LENGTH_SHORT).show()

}

override fun onStop() {
super.onStop()
Toast.makeText(this, "Activity is stoped", Toast.LENGTH_SHORT).show()

}

override fun onRestart() {
super.onRestart()
Toast.makeText(this, "Activity is again started", Toast.LENGTH_SHORT).show()

}

override fun onDestroy() {
super.onDestroy()
Toast.makeText(this, "Activity is destroyed", Toast.LENGTH_SHORT).show()

}
}

For more understand activity life cycle please override all methods and add break points in all methods and debug your app.

Thank you🙏🙏🙏🌹❤

--

--

Sudish Kumar

Teach lead, Flutter Developer, Android Developer, Node Js Developer