Task and Back Stack


Task is the collection of activities which are associated with a specific job. All the activities within a task are arranged in the form of a stack (Back Stack), the most recent one being on top the stack.

The list of all the tasks can be seen by clicking on the recents button.

tasks.png
List of all the tasks on clicking recents button

An application can be associated with more than one task. The dumpsys tool shows the list of tasks and other information pertaining to the tasks.

abd shell dumpsys activity activities

dumpsys.png
The image shows only a snapshot of this command. A detailed description of each task record can also be seen.

So, basically each task consists of a Task id and it consists of a Task Record which contains multiple Activity Records arranged in the form of back stack.


TaskRecord{107eea #6709 A=com.tfs.consumer U=0 sz=2}
Run #3: ActivityRecord{6396205 u0 com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity t6709}
Run #2: ActivityRecord{260e4da2 u0 com.tfs.consumer/.SplashScreenActivity t6709}

The expanded version of one Task Record from the dumpsys image is shown with two Activity Records. The Task ID is 6709.

Pointers

  • This concept of task and back stack make the Multitasking possible in Android.
  • If a task of an application exists and if we open the same application is opened from the launcher, the task comes to the foreground. If the application’s task does not exist, a new task with the new instance of the activity is added at the root of the stack.
  • These tasks can be killed by the Android system if the system runs low on memory.

 


Leave a Reply

Your email address will not be published. Required fields are marked *