Learn tech

Activity States & Stack in Android. EASY explanation!

An activity is one of the key components of an Android application. It provides the user with an interface to interact with. Imagine if your smartphone screen was pitch black, you won’t be able to see any button or features of the app. Hence, you can’t interact with it.
In simple words, activity is anything that you do on your Android device. There are four states in which an activity can be during its lifetime.

1. Active
As the name suggests, this state means that the activity is up running and active. It is visible to the user to interact with. An activity in the active state is always on the top of the activity stack. What’s an activity stack? It is a stack that stores the different activities as they occur. For example, you started playing a song in the music player. This will PUSH the music player on the empty stack, so now it is on the TOP of the stack. Now, assume that you went on to check your Instagram feed with the music playing in the background. The music player now gets PUSHed down in the stack and Instagram gets placed on TOP because it’s currently active and has the highest priority.

2. Paused
In this state, the user can see the activity but can’t interact with it. An example of this is when you’re chatting on Whatsapp and you pull down the notification panel from above. In this situation, Whatsapp is paused, you can see it partially being transparent.

3. Stopped
When you press the home button on your smartphone, the current activity isn’t destroyed, it justs goes invisible, waiting in the background. If you restart the activity, it will retain its previous state.

4. Destroyed
Here, the activity is destroyed i.e, removed from the activity stack. If you restart the activity, it will not retain its previous state. It begins refreshed.

If there are any doubts let me know in the comments below! or shoot me a mail at garimashares@gmail.com

Advertisements

0 comments on “Activity States & Stack in Android. EASY explanation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: