In this article I am going to discuss about Android Activity, Activity Stack, Register an Activity .

Activity :

One of the fundamental building block of Android app development is Activity. An activity represents a single screen in Android app with which user can perform a single, focused task such as dial the phone, take a photo, send an email, or view a map. Activities are usually presented to the user as full-screen windows.

An Activity is an application component that provide a single focused screen in Android App with which user can interact in order to do something . Activity is the main component of android app, which is displayed as a single window to the user, handles user events and provides behavior for a screen. An Activity helps us to creating a window for user , where we can place our UI with setContentView(View) .

An app usually consists of multiple activities that are loosely coupled to each other. Generally, one activity in an application is specified as the “main” activity, which is presented to the user when the app is launched. Each activity can then start other activities in order to perform different actions.

Activity Stack to manage the Activity :

Activities in the system are managed as activity stacks. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the “back stack”). When a new activity starts, that new activity is pushed onto the back stack and takes user focus. The back stack abides to the basic “last in, first out” stack mechanism, so, when the user is done with the current activity and presses the Back button, that current activity is popped from the stack (and destroyed) and the previous activity resumes.

All activities are work together to form a cohesive user experience in an app, each activity is only loosely coupled to the other activities. Typically, there are minimal dependencies between the activities in an app. Activities often start up activities belonging to other apps. For example, a browser app might launch the Share activity of a social-media app.

To use activities in our app, we need to register information about them in the app’s manifest, and we have to manage activity life-cycles appropriately.

Register Activities :

To register the information about activity, open the manifest file(AndroidMainfest.xml) and add an element as a child of the element and the required attributes, in the manifest. For example:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
  <application ... >
      <activity android:name=".TestActivity" />
  </application ... >
</manifest >

Android activities are started or activated with an intent. Intents are asynchronous messages that we can can use in our activity to request an action from another activity (or other app component). We use intents to start one activity from another and to pass data between activities.

In our next article we will discuss about Create and Start an Activity and The Activity Life-cycle, so stay tuned with us . Thank you 🙂

%d bloggers like this: