Difference between task and process in Android

Everything I’ve ever learned about it, I’ve learned on this page.

Edit: I also just stumbled upon Activity and Task Design Guidelines. It looks to cover the exact topic you asked about. I learned a lot 🙂

So basically activities from different
processes can be contained in the same
stack. Am I correct?

Based on my understanding, you are correct. My grasp is that Processes are the units of actual execution while Tasks are about association to get things done. As an example from the aforementioned page, if you create an intent that opens a webpage, the Activity that it creates is created on the web browsers process but is associated with your applications Task. A task, therefore, becomes a virtual stack of Activities running on different processes depending on the application that provided the Activity.


Another question: What is the real
meaning of “application context”? The
process or the task?

This is a good question. Based on reading the page above, my understanding is that an Applications context is associated with the process. I’m basing that on the interpretation of this line from that page, but there may be other info:

Normally, a new instance of an
activity is launched into the process
of the application that defined it, so
all instances of the activity run in
the same process


And final question: The application
class (which is basically a singleton)
represents the process or the task?

With the same interpretation as above, my guess as to why an Application object represents a Singleton is because all of your applications activities get run on a single process and that process is tied to the Application. I don’t know that this is a design point, but it appears to be, at the least, a consequence of the current design.

Edit: There are some caveats to this. It appears that your application can be spread across multiple processes so, my guess is that the Application Object and context act as a mechanism for tethering all the processes together. I’m pretty sure your mental model already allowed for this, assuming the processes were from different applications, so its only a small difference to allow it inside a single process.

The manifest element has the attribute android:process with the description as follows:

The name of the
process in which the activity should
run. Normally, all components of an
application run in the default process
created for the application. It has
the same name as the application
package. The element’s
process attribute can set a different
default for all components. But each
component can override the default,
allowing you to spread your
application across multiple processes.
If the name assigned to this attribute
begins with a colon (‘:’), a new
process, private to the application,
is created when it’s needed and the
activity runs in that process. If the
process name begins with a lowercase
character, the activity will run in a
global process of that name, provided
that it has permission to do so. This
allows components in different
applications to share a process,
reducing resource usage.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)