Sitemap
Arpita Gunjal

Arpita Gunjal

5 min readMar 14, 2026

--

Understanding Android Activity Lifecycle with Real-Life Examples (A beginner-friendly guide for Android developers)

  1. Introduction :
    Have you ever opened a mobile app, switched to another app, and then returned to the first app without it restarting completely?
    This smooth behavior is possible because of the Android Activity Lifecycle.
    In Android development, every screen you see in an app is called an Activity. Android manages these activities through a lifecycle — a set of states that an activity goes through from creation to destruction.

Understanding the Activity Lifecycle helps developers:
1.Manage memory efficiently
2.Prevent app crashes
3.Save user data
4.Create smoother user experiences

In this blog, we will explore the Android Activity Lifecycle using simple real-life workflow examples so beginners can easily understand it.

2. Why Activity Lifecycle is Important :

Android apps run on devices with limited memory and resources. Because users constantly switch between apps, Android must manage which activities stay active and which are stopped or destroyed.

Without lifecycle management, apps could:
➢ Crash when switching between screens
➢ Lose user data
➢ Consume too much memory

The Activity Lifecycle helps Android decide:
1. When to create an activity
2. When to show it
3. When to pause it
4. When to stop it
5. When to destroy it

Understanding this lifecycle allows developers to write efficient and reliable Android apps.

3. Real-Life Workflow Example (Using a Mobile App)

Let’s imagine you are using a Music Player App.
Your workflow might look like this:

  1. You open the app → Activity starts .
  2. The app becomes visible → Activity starts running
  3. You interact with the app → Activity is active
  4. You receive a phone call → Activity pauses
  5. You return to the app → Activity resumes
  6. You close the app → Activity is destroyed

This process is controlled by six main lifecycle methods.

4. Explanation of Each Lifecycle Method :

  1. onCreate()
    Technical Meaning :
    onCreate() is the first method called when an Activity is created.

It is used to:
• Initialize components
• Set the UI layout
Bind variables
Load initial data

Real-Life Analogy : Imagine opening a shop in the morning. Before customers arrive, you:
▪ Unlock the shop
▪ Arrange products
▪ Turn on lights
▪ Similarly, onCreate() prepares the activity.

Code Example :

@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
System.out.println(“Activity Created”);
}

2. onStart()
Technical Meaning :
onStart() is called when the activity becomes visible to the user.
The activity is not yet interactive but can now be seen.

Real-Life Analogy :Your shop doors are open, and customers can see inside, but you haven’t started serving them yet.

Code Example

@Override protected void onStart() {
super.onStart();
System.out.println(“Activity Started”);
}

3. onResume()

Technical Meaning : • onResume() is called when the activity comes to the foreground and the user can interact with it.
• This is the active state.

Real-Life Analogy : ▪ Customers are now inside the shop and actively buying products. ▪ Your shop is fully operational.

Code Example :

Get Arpita Gunjal’s stories in your inbox

Join Medium for free to get updates from this writer.

@Override protected void onResume() {
super.onResume();
System.out.println(“Activity Resumed”);
}

4. onPause()

Technical Meaning :

• onPause() occurs when the activity is partially hidden by another activity. • The user might still see part of it but cannot interact fully
• Developers should save temporary data here.

Real-Life Analogy : ▪ You step away from your shop counter to answer a phone call.
▪ The shop is still open, but you are not actively serving customers.

Code Example :

@Override protected void onPause() {
super.onPause();
System.out.println(“Activity Paused”);
}

5. onStop()

Technical Meaning : • onStop() is called when the activity is completely hidden from the user.
• The activity is no longer visible.

Real-Life Analogy : ▪ You close the shop for a while, but everything is still inside.
▪ You may reopen it later

Code Example :

@Override protected void onStop() {
super.onStop();
System.out.println(“Activity Stopped”);
}

6. onDestroy()

Technical Meaning : • onDestroy() is called when the activity is completely destroyed and removed from memory.
• This happens when:
• The user closes the app
• Android needs memory

Real-Life Analogy : You shut down the shop completely and lock it.
▪ Everything is closed.

Code Example :

@Override protected void onDestroy() {
super.onDestroy();
System.out.println(“Activity Destroyed”);
}

diagram:

7. Complete Lifecycle Code Example :

public class MainActivity extends AppCompatActivity
{
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
System.out.println(“onCreate called”);
}
@Override protected void onStart()
{
super.onStart();
System.out.println(“onStart called”);
}
@Override protected void onResume()
{ super.onResume();
System.out.println(“onResume called”);
}
@Override protected void onPause()
{ super.onPause();
System.out.println(“onPause called”);
}
@Override protected void onStop()
{
super.onStop();
System.out.println(“onStop called”);
}
@Override protected void onDestroy()
{
super.onDestroy();
System.out.println(“onDestroy called”);
}
}

8. Summary Table

Press enter or click to view image in full size

➢ The following diagram illustrates how Android manages the lifecycle of an Activity as users interact with an application.

Press enter or click to view image in full size

9. Best Practices for Developers :
Save important data in onPause()
Users may switch apps anytime, so save progress.

Release heavy resources in onStop()
Example:

• Camera • Sensors • Location services

Avoid heavy tasks in onCreate()
Long operations here can slow app startup.

Use lifecycle-aware components
Android Jetpack components like ViewModel help manage lifecycle automatically.

10. Conclusion :

The Android Activity Lifecycle is one of the most important concepts for building reliable Android apps.
By understanding how Android manages activities, developers can:
• Create smoother user experiences
• Prevent crashes
• Manage resources efficiently

Remember the simple flow:
Create → Start → Resume → Pause → Stop → Destroy
And just like running a shop or workplace, every stage has a specific responsibility.
Mastering this lifecycle will make you a better Android developer and help you build professional, user-friendly applications.

References :
1. Android Activity Lifecycle — Official Documentation https://developer.android.com/guide/components/activities/activity-lifecycle
2. Android Programming: The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, and Kristin Marsicano.
3. Head First Android Development by Dawn Griffiths and David Griffiths. 4. Google Developers — Android Developer Training https://developer.android.com
5. Android Studio Documentation and Logcat examples used for lifecycle testing.

--

--