Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Android App Lifecycle: Part 1

2 min readOct 25, 2023

--

Press enter or click to view image in full size

In this tutorial, I will teach you about the Activity Lifecycle in Android. This is something you haven’t seen before on any YouTube or other tutorials.

Introduction

In Android, there are several methods that are present in the superclass Activity. These methods are executed one by one when you run your application. In previous tutorials, we have only used the onCreate method. In this tutorial, we will see the significance of all the other methods and understand how they are executed.

Activity Lifecycle

When you launch your application, the following methods are executed in order:

  • onCreate
  • onStart
  • onResume

At this point, the activity is visible to the user and they can interact with it. In our example, we have a button in Activity A that allows the user to navigate to Activity B.

When the user clicks the button, the following methods are executed:

  • onPause (in Activity A)
  • onCreate (in Activity B)
  • onStart (in Activity B)
  • onResume (in Activity B)

Now, Activity B is visible to the user and they can interact with it. Activity A is in the paused state.

Get Birbal Jaat’s stories in your inbox

Join Medium for free to get updates from this writer.

If the user presses the back button, the following methods are executed:

  • onPause (in Activity B)
  • onStop (in Activity B)
  • onRestart (in Activity A)
  • onStart (in Activity A)
  • onResume (in Activity A)

Now, Activity A is visible to the user again and they can interact with it. Activity B is destroyed.

If the user presses the back button again, the following methods are executed:

  • onPause (in Activity A)
  • onStop (in Activity A)
  • onDestroy (in Activity A)

Now, both Activity A and Activity B are destroyed and nothing appears on the screen.

Conclusion

Understanding the Activity Lifecycle is important when developing Android applications. It allows you to control the behavior of your application at different stages. In the next tutorial, we will dive into the code and see how these methods work in Android Studio.

If you found this tutorial helpful, please clap for this tutorial and leave a comment below the tutorial. Thank you and have a good day!

Stackademic

Thank you for reading until the end. Before you go:

  • Please consider clapping and following the writer! 👏
  • Follow us on Twitter(X), LinkedIn, and YouTube.
  • Visit Stackademic.com to find out more about how we are democratizing free programming education around the world.

--

--

Birbal Jaat
Birbal Jaat

Senior Software Engineer @Mobile Programming LLC

Stackademic
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.