Android Tasks and Activity backstack!

The Android system keeps linear navigations of the history of the activities traversed called backstack. Using the BACK key, user can get to the previous activities in the order they get into the stack. The BACK key limits to show the activities further than the last visit to the HOME. Adding an activity to the current stack is regardless of whether the activity is in the same task or begins a new one. A task consists of one or more than one activities that the user uses to accomplish an objective (like any given transaction). Hence the backstack can be of more than one activity in one task or more than one task. In the later case, going back can let the user go back to activities in previous task. To switch between tasks user can selects its root activity from the application launcher. Activity that starts a task is a root activity. Until a new task is explicitly specified, all activities the user starts are considered to be in the same task. Hence the BACK key helps to get to the previous activities in this task. It is possible to have two tasks running simultaneously and user can jump between these tasks to perform actions. This can be done by pressing the HOME key. E.g. if from Home page Application A is started which starts Activity 1. It’s a new task. Activity 1 starts Activity 2. While the user is in Activity 2, some action needs to be performed in Application B which has Activity 3. Activity 3 has to be started from HOME. So the user press HOME and starts Application B (new application, new task) and perform some actions. Remember the Activity 2 in previous task is stopped not destroyed and hence it can be regained in the state it was left once the user again go to HOME and get back to the previous task. Hence the flow can be: HOME->Application A(Task 1)->Activity 1->Activity 2 ->HOME -> Application B (Task 2)->Activity 3 ->HOME->Application A(Task1)->Activity 2(restore the state as left)

Starting a new task:

* Act to a notification
* Press HOME and start a new application
* Start an activity that defines a new task (done explicitly)

A single task can comprise of more than one application. Starting a new application from the current activity is in the same task. To conclude, when a user act to a notification or start a new task explicitly, the backstack consists of more than one task. A new task started by beginning a new application from the HOME, the traversing of activities through BACK leads to same task.

Contributed by Purvi Patel, SDE Android – TringApps Inc


15 thoughts on “Android Tasks and Activity backstack!

  1. Rajesh Prakash says:

    Android specializes by the role of Activity manager as it manages the entire lifecycle of applications, maintains the common back stack and smooth integrated navigation experience for applications running on different processes.

    • Application run in their own process.
    • Processes are started and stopped as needed to run application components.
    • Processes may be killed to acquire resources.
    1. Before every new activity is launched the previous activity is stored in the system
    2. Create a request in order to launch a new activity.
    3. Can take the same stored information from the system process and restore in the activity when it navigate backward.
    4. Helps the user to navigate backward as they navigate forward.

    Some of the other cool API’s:

    1. Location manager – Geographical location, create the notification for current location
    2. XMPP service – Sends the device to device data messages.
    3. Notification manager – can use the notification manager for any of the application.
    4. View – Grid, List, Gallery view, buttons and check boxes, Map view, web view.

  2. mobisynth says:

    Guys All you need to do is use MS-Word before you write your comments. For the most part it will help you get rid of your grammar issues. It reflects really bad on the team if a Business Manager has written incorrect english. Please fix the grammar issues Rajesh.

  3. Priya says:

    A task is the sequence of activities the user follows to accomplish an objective. In Android tasks, users can run multiple tasks simultaneously and switch between them.
    Back stack and activity stack are same.( In Android activity lifecycle, the activities are managed as activity stack. That is when a new activity is started it will be on the top of the stack and become the running activity. Previous activity will always remain below it in the stack. Once the new activity exits, the Previous activity will start running.)

  4. GIRIDHARAN N says:

    I feel that the there will some pointer pointing to the stack entries and position of which will be changed according to the user actions or actions performed(like going to a new task), the pointer will point to the new activity as when they are added. So that you can move to the backwards till the start of that stack(terminal).

  5. Padmavathy says:

    We have launch modes in the android, which are used to specify that how the activities can be used. They are “standard” (the default mode), “singleTop”, “singleTask”, and “singleInstance”.

    “standard” and “singleTop” – In these modes the activity will be launched in the same task, from where we have started the activity. Flag FLAG_ACTIVITY_NEW_TASK is used to start the activity in the new task. There may be multiple instances of these activities in a task and one activity may belong to multiple tasks. Instances of these activities may appear anywhere in the stack. There is a difference between “standard” and “singleTop” – In case of “standard” a new instance will be created to respond to a new intent, where as in “singleTop” – If the activity is already there in the top of the stack then this instance will be reused to handle the new intent, otherwise the new instance will be created.

    “singleTask” and “singleInstance”– These modes define a task and they never launched in to another task. These activities are always at root of the task and only one instance will be created for these activities. There is a difference between “singleTask” and “singleInstance”- A “singleInstance” activity is the only activity in its task, it can be started in the different task with the flag FLAG_ACTIVITY_NEW_TASK, where as “singleTask” activity can start other activities in the same task.

  6. I feel linked list will be used in this process. Because if stacks are used the current running application will be on the top of the stack and the application which was running before will be below the last one. So if we switch through different application in different order, the processing speed will be slow.

  7. Arunachalam says:

    Back Stack is an interesting thing while one creating an application.

    * It would be very useful if the mobile keeps the history of the activities traversed. Switching between the current activity to the previous one will lead no time to wait.

    By pressing Back key the current process gets destroyed. But a new activity keeps the current one in running state or paused state.

    Due to this, redundancy of processes occurs when a same activity is opened once again and It takes some more time to load the same page.

    The Processes which all are running background also increases the load without any use.

    Re-Usability of the previous process will eradicate these kinds of problem. Because, the mobile has the little resource of processor and memory to be utilized.

    Sometimes it is assential to keep the current activity even the user presses the Back button. As an example, If the user plays some music, It should keep on running in the background if he goes Back.

    A good programmer plays an important role here. Thus the Back stack plays an interesting and important role in case of mobile based application developments.

  8. Ravi Joshi says:

    Whenever the user launches an application from one of the activities while being in the same task or by creating a separate task (by launching it from HOME) the components of the application may run in the same process or several processes. The execution of a component in a particular process is controlled by a manifest file.
    In the former case, when the user has launched a a number of applications while staying in the same task, navigating through the activity Back Stack will be slower because it will pursue that at the expense of several process switches.
    And in the later case, when the user launches a number of application by creating new tasks and if the user remains away from a task for a longer time the system reclaims the resources from the activities in that task thereby causing the application to lose its recent activities state . Thus when the user returns to the application (task) only the initial activity is present.

  9. Siddhesh Naik says:

    If the user switches through different application activities in different order, the an tree structure would be helpful to increase the performance.
    This is because, every time a switch is to be made between applications, the user presses the Home button. So the Home is the root of the tree. The root can have any number of children. These children would represent applications, with the leaf nodes representing active activities.

  10. David Wang says:

    Task can be regarded as an application, activity can be regarded as a user event, like one can listen to music with a player, and search preferred songs with the player built-in plug-ins. It is like one process sliced in multiple execution flow, say, thread.

    Google`s products always give me a sense that the concepts in computer science are strictly implemented, it is also why I like Google so much: )

    If I implement this feature, I would probably design an array of pointers, which is built and maintained by some manager module at runtime. Pointers points to some area on a heap. Once the state information needs to be stored for some reason, store in some positions on the heap and link the according pointer to the UI element of that task. I would take a limited size array, just like mimix process pool, this avoids extra space cost and allows faster access speed. Storage and access response time is essential for handheld devices, though it may limit the function, but a user is not supposed to be too extreme, like running 200 or more application at the same time on just a handheld device.

    And the manner that every time one wanna start a new task must return home menu, is something like vim, or some other command line tool. User who get used to them may probably feel comfortable with this: )

  11. Yatin says:

    As I understand, with the BACK key the navigation is limited to the last HOME page visit, thus for earlier history, users needs to select the root activity.

    The stack stores activities only and not stuff like views, windows etc. In case we need to store them on the stack, we need to implement them as activities.

    Also, different activities are bound at runtime, thus we can re-use them in different applications.

  12. Activity back stack
    -keep tracks the history in linear navigation order
    -in stack the history arranged like stack if we press BACK key it will go to immediate action performed before

  13. Sasi says:

    A task is a collection of activities that users interact with when performing a certain job. The activities are arranged in a stack (the “back stack”), in the order in which each activity is opened.

    An activity can even start activities that exist in other applications on the device. For example, if your application wants to send an email, you can define an intent to perform a “send” action and include some data, such as an email address and a message. An activity from another application that declares itself to handle this kind of intent then opens. In this case, the intent is to send an email, so an email application’s “compose” activity starts (if multiple activities support the same intent, then the system lets the user select which one to use). When the email is sent, your activity resumes and it seems as if the email activity was part of your application. Even though the activities may be from different applications, Android maintains this seamless user experience by keeping both activities in the same task.

  14. Vijaya Rekha says:

    An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

  15. sakthiboobalan says:

    I had doubt in back stack. consider that an application has more number of activities, i opened that and navigating to all the activities finally stack was full. now what will happen?

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s