Android Activity – Activity Lifecycle | Android ActivityManager

Android Activity is one of the components of Android. It represents a single screen in your application.  We can say that it performs actions on the screen.

An application can have zero or more activities. Typically, applications have one or more activities.

The main aim of Activity is to interact with the user. From the moment an activity appears on the screen till the time it is hidden.

Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the “back stack”).

Each time a new activity starts, the previous activity is stopped. However, the system preserves the activity in a stack (the “back stack”).

Android activity goes through a number of stages, known as an activity’s lifecycle.

There are 7 stages in Android Activity lifecycle. ActivityManager manages these activities and shows what state your activity is.

7 methods of Android Activity Lifecycle

  1. onCreate()
  2. onStart()
  3. onResume()
  4. onPause()
  5. onStop()
  6. onDestroy()
  7. onRestart()

 

The Activity can be destroyed from onStop() or onRestart() methods, let us understand the functions of each of these methods below:

Created

In this method, activity should create its UI.

Started

In this state activity is about to start, it is completely invisible.

Resumed

In this state Activity’s UI is completely visible on the screen.

Paused

Activity is about to unload or cover because of another activity, in this state activity is completely visible on the screen.

Stopped

Activity is unloaded or another activity has fully covered the first activity, in this state activity is completely visible.

Destroyed

In this state, activity is already unloaded and about to get destroyed.

Restarted

In this state, activity is about to restart because of uncovering.

The following figure explains the Activity Life Cycle:

Android Activity
Activity Lifecycle

Declare the Activity in AndroidManifest.XML file with intent filters:

The <action> element shows that this is the “main” entry point to the application and The <category> element allow users to launch this activity.

The best way to understand the various stages experienced by an activity is to create a new application and implement the various events.

After creating the application, inside our MainActivity we have to implement all the methods one by one and we can see all the events very well with the help of LogCat.

Team RCV Academy

About Team RCV Academy

RCV Academy Team is a group of professionals working in various industries and contributing to tutorials on the website and other channels.

View all posts by Team RCV Academy