Android App Development Certification Trainin ...
- 55k Enrolled Learners
- Live Class
In our previous posts, we have explained how to create Android apps and games. However, those Android tutorials might appear advanced to a beginner with limited knowledge of the technology. Our series of Android Tutorials would help beginners get familiar with the basic concepts of Android. This Android tutorial discusses the activity component.
Let us take the example of your very own Facebook app. The log in screen is the first activity you see when you launch your Facebook app. After signing in, the next activity encountered is the news feeds screen.
To develop a successful application, it is important for the developer to map out the complete flow of activities based on the user’s action. This would ensure that the application behaves exactly as expected. Therefore, understanding the Activity Life-cycle is very important for developers.
Following are the different states in an Activity Life-cycle:
1) Starting State:
When an activity does not yet exist in memory, it is in the starting state.
2) Resumed/Running State:
An activity that is in the foreground is in the running state. Any activity that is currently on the screen and interacting with the user is the running activity at that particular point in time. It exists at the top of the activity stack.
3) Paused State:
When an activity is not in focus (i.e. not interacting with the user), but is still visible on the screen, it is in the paused state.
4) Stopped State:
An activity that is not visible on the screen, but exists in the memory is in the stopped state.
5) Destroyed State:
A destroyed activity results from the removal of an activity (that is no longer required) from the memory. Such removals generally occur, when the activity manager decides that there is no use for such activities anymore.
The activities go through their life-cycle using a stack mechanism. “Last in-first out” system operates in the Android Activity stack. Here’s a brief overview of how the Activity Back-stack works:
Whenever an activity goes through any change in its life cycle stages (for instance: When a running activity is paused), a callback method notifies it of this change. Whether the activity is being created, destroyed, or undergoing any other transition, there is a callback method to notify it. For each callback, there is a pre-defined behavior.
To ensure smooth transitions between different activities, the developer must implement callbacks beforehand. We shall discuss more on callbacks in subsequent Android tutorials. Stay put for that.
Got a question for us? Please mention it in the comments section and we will get back to you.