Activity In Android
The Activity class is a critical component of an Android application, and the way activities are launched and bundled is a fundamental part of the platform’s application model. Unlike programming paradigms in which applications are launched using the main() method, the Android system initiates code in an Activity instance by calling specific callback methods corresponding to specific stages in its life cycle.
A mobile app differs from its desktop counterpart in that the user’s interaction with the app doesn’t always start in the same place. Instead, the user’s journey often begins non-deterministically. For example, if you open the email app from the home screen, you can see a list of emails. In contrast, if you’re using a social networking app that then launches your mail app, you can go directly to the mail app’s screen to compose an email.
The Activity class is designed to implement this paradigm. When one application calls another, the calling application invokes an action in the other application, not the application as an atomic whole. Thus, the action serves as the entry point for the application to interact with the user. You implement an activity as a subclass of the Activity class.
An activity provides a window in which an application draws its user interface. This window usually takes up the entire screen, but can be smaller than the screen and float on top of other windows. Typically, one action implements one screen in an application. For example, one of the application’s actions could implement a settings screen, and another action could implement a photo selection screen.
Most apps contain multiple screens, which means they include multiple actions. Typically, one activity in an application is listed as the main activity, which is the first screen that appears when the user launches the application. Each activity can then start another activity to perform different actions. For example, the main activity in a simple email application might provide a screen that displays an email inbox. From there, the main activity can launch other activities that provide screens for tasks such as writing emails and opening individual emails.
While activities work together to form a cohesive user experience in an application, each activity is only loosely coupled to other activities; there are usually minimal dependencies between activities in an application. In fact, actions often trigger actions that belong to other applications. For example, a browser app might trigger the “Share” action of a social media app.
In order to use activities in your application, you must register information about them in the application manifest and properly manage activity lifecycles. The rest of this document introduces these topics.