salman khalid
salman khalid

Reputation: 4934

Difference between Running Task and Running Process in Android

Can any one please tell me what is the difference between Task and Process in Android. If I use this code snippet.

ActivityManager Appmgr;
protected List<ActivityManager.RunningTaskInfo> apps;
protected List<ActivityManager.RunningAppProcessInfo> applications;
applications = Appmgr.getRunningAppProcesses();
apps = Appmgr.getRunningTasks(30);

Whats the difference between applications = Appmgr.getRunningAppProcesses() and apps = Appmgr.getRunningTasks(30).

Please Help me. Regards

Upvotes: 9

Views: 3886

Answers (3)

user370305
user370305

Reputation: 109237

getRunningAppProcesses () :

Returns a list of RunningAppProcessInfo records, or null if there are no running processes (it will not return an empty list). This list ordering is not specified.

getRunningTasks (int maxNum) :

Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.

Update:

Now the difference between Task and Process.

In Android a Task is a set of or you can say a collection of Activities. Its all about user interaction with these activities. Android maintains these activities in stack accordingly they are opened and maintain this stack. May be one stack or many stacks, the last opened activity on top of stack. And it hows android maintain systems's state. An Application has its own task with it opened activities and if new Application starts, system creates a new Task with new Activities in LIFO structure. And when user interacting with this task on Home Screen, He just navigate to particular application and task of this application now become foreground.

While Process is related to Android application component. Every new Android application start in new Process (Linux Process) in its own user space. All application components run on same Process by default. And it execute as single thread process. That's why its called Main Thread of Application. But here you can define separate process for different android application components, like Activity, Service, Provider or Broadcast Receiver using manifest attribute android:process. Android Process has same funda as Linux Process with UserId, so you can combine different android application components running on same process with same UserId.

So while you call getRunningAppProcesses() It will give you all running Android application's processes related to running application components.

And getRunningTasks (int maxNum) gives you list of created task for different running applications by systems while user interact with applications.

Upvotes: 7

Aniket Thakur
Aniket Thakur

Reputation: 68915

Android has Linux kernel. So process is similar to processes in Linux. Each process can have multiple threads. When a process starts it is single thread execution by default. This thread is called the main thread or UI thread. You may have other worker or asynchronous threads running in a process.

Task or Application on the other hand can be visualized as set of activities in an application. It is possible that each activity in the task is configured to run in different processes. Same goes for other entitles of Android - services, providers etc. Infact components of different tasks/applications can run in same process (provided that the applications share the same Linux user ID and are signed with the same certificates).

When System memory is low of running application an older process is killed. Again note this may have components of different application.

activityManager.getRunningTasks(Integer.MAX_VALUE)

Above will give you Running tasks or rather lets call it application consisting of set of activities. (List of RunningTaskInfo objects). This in turn will have two main things.

  1. baseActivity : component launched as the first activity in the task
  2. topActivity : activity component at the top of the history stack of the task

and

activityManager.getRunningAppProcesses()

Above will give all running processes in the System. Since it is a process it will have associated pid (processId) and `uid (userId). Some of the important fields here are -

  1. processName : The name of the process that this object is associated with
  2. pid : The pid of this process; 0 if none
  3. uid : The user id of this process.
  4. pkgList : All packages that have been loaded into the process.

Upvotes: 3

Simon
Simon

Reputation: 81

The previous "answer" is replacement of one unknown subject by another. The question is about system definition, not about how to receive related information and difference between methods and classes.

Actually in the Android task= application and is set of activities.

Process is division by memory separation and is set of threads running is separated memory.

By default application is a process. By developer is able to define another separation by processes by means of use of the "android:process" attribute in the "activity", "service", "receiver" and other definition of executable units inside the manifest time.

See http://developer.android.com/guide/components/processes-and-threads.html

Upvotes: 8

Related Questions