Monday, March 16, 2015

Tasks and Back Stack

Tasks and Back Stack

- 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.

- When the user touches an icon in the application launcher 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 new activity is started, it's pushed in to back stack. The previous activity stopped and system retains it current 
 user interface state. When user presses back key , activity which is in top of back stack is popped and destroyed by system
 and previous activity just resumes its state. 
 
 
Managing Tasks: Application allows users to start a particular activity from more than one activity, a new instance of that activity is created and pushed 
                onto the stack . one activity in your application might be instantiated multiple times. you can modify this behaviour if you do not want an 
activity to be instantiated more than once using below methods.

launchMode: 
- "standard"
- "singleTop"
- "singleTask"
- "singleInstance"

Using Intent flags

- FLAG_ACTIVITY_NEW_TASK
- FLAG_ACTIVITY_SINGLE_TOP
- FLAG_ACTIVITY_CLEAR_TOP

Clearing the back stack: If the user leaves a task for a long time, the system clears the task of all activities except the root activity. 
When the user returns to the task again, only the root activity is restored. 

- alwaysRetainTaskState: retains all activities in its stack even after a long period, if this attribute is set to "true" in the root activity of a task.
- clearTaskOnLaunch: The user always returns to the task in its initial state, even after a leaving the task for only a moment.
- finishOnTaskLaunch: This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an entire task.

0 comments:

Post a Comment