Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Running Task and Running Process in Android

Tags:

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

like image 899
salman khalid Avatar asked Nov 16 '11 08:11

salman khalid


2 Answers

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

like image 110
Simon Avatar answered Sep 29 '22 19:09

Simon


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.

like image 35
user370305 Avatar answered Sep 29 '22 19:09

user370305