We had a quick glance on “What an android activity is?” in our previous post, here we are going to discuss about Life cycle involved in an android activity.
Activity in the system is managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity — the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits. It might be little bit confusing, let me explain it with an example:
Assume you open Facebook app in your android mobile, you are looking through the shares/posts posted by your friends and you are coming across one interesting web link posted by your friend. You click on the link to view what is there inside, it takes you to web browser and open up the website.
In this post, we are going to discuss about ‘Activity’, for newbies the term ‘Activity’ might be looking like a jargon. Let us discuss it with a very simple example.
What is an Activity?
Activity is a Java code that supports a screen or UI. In other words, building block of the user interface is the activity.
Activity class is a pre-defined class in Android and every application which has UI must inherit it to create window.
Let us create a simple application which displays current time when you just tap the window. We will dissect the code to understand how the activity works.