Android Activities

Introduction to Android Activities

Activity, as previously discussed in User Interface in Android, is a single screen for user interaction. Activity takes input from the user and gives output to the user. Android Activity is composed of views and view groups. An Application has single or multiple Android activities. Activities are loosely bound to each other, which means that it is not necessary for any activity to have any prerequisite activity. Any activity can start another activity. The only restriction in the case of activities is that only one activity can run at a time, the previous activity must stop before starting another activity.

Working of Android Activities

When any activity starts, it is pushed into the back stack and gets the focus on the screen. The back stack strictly follows LIFO (Last in, First out) i.e. stack mechanism. Whenever the user presses the back button current activity is popped out from the stack and destroyed and the previous activity resumes.

Lifecycle of Android Activity

When any activity stops because a new activity starts, the state changes and is notified through activity call back methods. There are several call back methods that an activity receives when its state change i.e. when the system is creating it, stopping it, resuming it or destroying it.

Lifecycle States of Android Activity

Created state is temporary. The system moves to the next state immediately.

Started state is also a temporary state. The system moves to the next state immediately.

This state is also known as running state. The activity becomes the foreground activity. The user can interact with the resumed i.e. running activities.

This state tells that the activity is temporarily stopped or the activity become semi-transparent i.e. it does not cover the entire screen. The user can not interact with the activity in the paused state.

In the Stopped state the activity is completely hidden and the user can not see it. The stopped activity is running in the background as the instance of the activity, its state information i.e. member variables and functions are retained, and it can’t perform any task.

There are some situations in which the activity can switch between states.

  • The Activity is in the stopped, paused and resumed state. Only these three states are static. The activity can exist between these states for a longer period.
  • The other States i.e. created and started are transient (temporary), and the system quickly moves from these states to the next state. The changing of state can be done by calling the next lifecycle callback method.
Android Activity Lifecycle
Android Activity Lifecycle (This image is taken from official Android developers documentation)

Android Callback methods

  • onCreate()
  • onRestart()
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • onDestroy()

Implementing Callback Methods in Android Activities

All the callback methods are implemented by overriding them. They are appropriately called when the state of the activity changes. You must call the superclass method’s implementation before performing any task.







These methods must be implemented after overriding and implementing onCreate() method within the activity.

To see when these callback methods are called during Activity’s lifecycle by using Log utility.


When you want to request any action from another app component or you, want to pass any message to another app component you can use intent. There are two types of intents.

  1. Implicit intents
  2. Explicit intents

Implicit Intent

Implicit intent does not call any specific app component; it generates a general action to be performed. This allows any other app’s component to handle the request. For example, if you want to use the camera, you need to call an implicit intent that will automatically call appropriate camera app to handle the request.


Explicit Intent

Explicit intent calls a specific app component to start by name i.e. Fully qualified class name. For Example, if you want to call any component of your app and you know the class name of any service or activity you want to start.


Passing extra message in intents

Sending extra message through intent

You can also pass an extra message to your intent for the next activity.

Receiving Extra Message through Intent

In the newly started activity, you can get an extra message which was sent by the previous activity.

Start Second Activity for Result

Send Results from Next/Second Activity

Receive Result in the Previous Activity

Read more about Android Activity