DEV Community

Collins Etemesi
Collins Etemesi

Posted on

1

Android Activity Lifecycle

In an Android app, the Android system uses activities to run code. The activity lifecycle is the different states that an activity can go through, from when the activity first initializes to its destruction.
Image description
The Activity class provides 7 callback methods that let the activity know when a state changes: onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), onDestroy().

onCreate()
The onCreate() lifecycle method is called once, just after the activity initializes—when the OS creates the new Activity object in memory. After onCreate() executes, the activity is considered created.

onStart()
The onStart() lifecycle method is called just after onCreate(). After onStart() runs, your activity is visible on the screen to the user. Unlike onCreate(), which is called only once to initialize your activity, onStart() can be called by the system many times in the lifecycle of your activity.

onResume()
This method is called when the activity will start interacting with the user. The user starts interacting with your app for this to happen.

onPause()
Always called after onResume() and when the user is no longer actively interacting with the activity but the activity is still visible on the screen.

onStop()
This is called when the activity is no longer visible on the screen to the user.

onRestart()
Called when the current activity is being redisplayed to the user. From the Stopped state, if the activity comes back to interact with the user the system invokes onRestart().

onDestroy()
is called before the activity is destroyed. The system invokes this callback either because, the user dismisses the activity, or there is a configuration change such as device rotation.

Thank you for reading this article. Happy Coding.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay