-3

I am new to Android Programming.

I want to understand how Activity Stack is maintained for a particular Android Application and how does it changes based on user navigation.

For example, if there are multiple activities then how Activity Stack behaves when user clicks on Back Button or Home Button or launches a new Activity?

I was trying to find a suitable post where I can get all the information, but I did not get any. Can somebody please suggest me some links/posts where I can learn this?

Thanks!

Edited:

Links/Posts that I came across so far:

  1. onSaveInstanceState is not saving my values ( onCreate input Bundle is always null )

  2. Saving Android Activity state using Save Instance State

  3. Android: Launch mode 'single instance'

Community
  • 1
  • 1
Saumik Bhattacharya
  • 891
  • 1
  • 12
  • 28

1 Answers1

3

Do you mean activities and the back stack?

Here is a link: http://developer.android.com/guide/components/tasks-and-back-stack.html

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.

The device Home screen is the starting place for most tasks. When the user touches an icon in the application launcher (or a shortcut on the Home screen), that application's task comes to the foreground. If no task exists for the application (the application has not been used recently), then a new task is created and the "main" activity for that application opens as the root activity in the stack.

When the current activity starts another, the new activity is pushed on the top of the stack and takes focus. The previous activity remains in the stack, but is stopped. When an activity stops, the system retains the current state of its user interface. When the user presses the Back button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored). Activities in the stack are never rearranged, only pushed and popped from the stack—pushed onto the stack when started by the current activity and popped off when the user leaves it using the Back button. As such, the back stack operates as a "last in, first out" object structure. Figure 1 visualizes this behavior with a timeline showing the progress between activities along with the current back stack at each point in time.

enter image description here

Frakcool
  • 10,915
  • 9
  • 50
  • 89
jMike
  • 307
  • 4
  • 12
  • jMike & @Nippey -- Thanks for the clarification! It almost answers my question. :) Just to add, what happens when user clicks on 'Home' button? – Saumik Bhattacharya Nov 06 '15 at 17:45
  • addition: Just to add, what happens when user clicks on 'Home' button? When you press the home button, onPause is called first followed by onStop. addition 2: I meant what happens to the Back Stack? The back stack for the task remains intact — the task has simply lost focus while another task takes place. – jMike Nov 06 '15 at 18:05
  • I meant what happens to the Back Stack? :) – Saumik Bhattacharya Nov 06 '15 at 18:39