Sitemap
Vikas Bajpayee

Vikas Bajpayee

Android Engineer at Gojek

Process vs Task

3 min readMay 29, 2020

--

Everyone in Android discusses Task but no one discusses about what is a process, in this blog I am going to explain what is the basic difference between a task and process. before that let us first understand what is a Task and backStack in android.

Task

A task is a collection of activities(screens), now these activities can be of different applications or from the same application. Activities of different applications invoked by the intent are put into the same Task.

BackStack

A Task contains multiple Activities and these activities arranged in a Stack called Back Stack. This Stack has LIFO structure and it stores the activities in the order of their opening. The Activities in the Stack are never rearranged.

Get Vikas Bajpayee’s stories in your inbox

Join Medium for free to get updates from this writer.

Activity’s Manifest attributes related to back stack:-

  1. noHistory - If this is set to true then it destroys the current Activity and removes it from the back stack whenever any other Activity is started by it. You don’t have to explicitly call finish for this activity. this attribute is effective in SplashActivity.
  2. clearTaskOnLaunch - If this attribute is set to "true" in the root activity of a task, the stack is cleared down to the root activity whenever the user leaves the task and returns to it. In other words, it's the opposite of alwaysRetainTaskState. The user always returns to the task in its initial state, even after leaving the task for only a moment.
  3. finishTaskOnLaunch - This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an entire task. It can also cause any activity to go away, including the root activity. When it's set to "true", the activity remains part of the task only for the current session. If the user leaves and then returns to the task, it is no longer present.
  4. alwaysRetainTaskState - If this attribute is set to "true" in the root activity of a task, the default behaviour just described does not happen. The task retains all activities in its stack even after a long period.

Example for the above attributes can check out here:-
https://stackoverflow.com/questions/22309876/relationship-between-androidnohistory-and-androidfinishontasklaunch

Now let’s dig deeper to understand the difference between process and task

Processes vs Task

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

Process — When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the “main” thread). Every application runs in its own process and all components of the application run in that process, by default.

--

--