The concept of tasks and processes in Android is a bit confusing. I saw a good article on the Internet and picked it up to record it ~~~
Http://bbs.sjtu.edu.cn/bbstcon,board,MobilePhone,reid,1288709685,file,M.1288709685.A.html
My personal understanding:
First, you can see that it is not a process, but a task ).
Using the terminal and PS, you can see the real running Linux Process. On my milestone, there are usually 90
Multiple.
In Android, app, process, and task are three completely different concepts ......
Process is a concept inherited from Linux. Generally, an app has a uid, and a p
Rocess. Some processes are used as APP containers, while other processes are used in underlying Linux. At the same time, although
It is rare that multiple apps share a process or uid.
A task is the stack of an activity, where "may" contains the activity from multiple apps, that is, the activity from multiple p
Rocess: Kill a task is generally to close the child tree derived from the root activity of the task. It may not necessarily kill the corresponding
Process.
So these three things will be mixed together, and there is no process boundary as clear as in Windows or other OS.
In the API, there is a activitymanager class for getting the items that are running. It can:
Getrecenttasks () for the recently opened task, press the Home Key to see this
Getrunningappprocesses () is running as the process of the app container.
Getrunningservices () running background service
Getrunningtasks () running tasks
So even in APIs, these things are not uniform.
If activity A is called by another task instead of the Root Activity of the task, the corresponding p
Rocess is open. Is it displayed?
In addition, if an app is only open with a service but no activity or task, isn't it open?
Different killer may have different filtering methods for key processes or services in the system, which may also
It will increase confusion to a certain extent.
In the end, there are no clearly defined task concepts in other operating systems in Android.
Defined, so it's confusing ......
Obtain the list of recently run programs:
Public void gettasklist () {<br/> imagebutton ivicon; <br/> activitymanager AM = (activitymanager) getsystemservice (activity_service); <br/> packagemanager PM = This. getpackagemanager (); <br/> try {<br/> List <recenttaskinfo> List = aM. getrecenttasks (64, 0); <br/> lltaskbar. removeallviews (); <br/> for (recenttaskinfo Ti: List) {<br/> intent = Ti. baseintent; <br/> resolveinfo = PM. resolve Activity (intent, 0); <br/> If (resolveinfo! = NULL) {<br/> ivicon = new imagebutton (this); <br/> ivicon. setimagedrawable (resolveinfo. loadicon (PM); <br/> ivicon. setfocusable (true); <br/> ivicon. setclickable (true); <br/> ivicon. setenabled (true); </P> <p> ivicon. setscaletype (scaletype. center); </P> <p> ivicon. setlayoutparams (New linearlayout. layoutparams (120,120); <br/> lltaskbar. addview (ivicon); <br/>}< br/>} catch (securityexception SE) {<br/> Se. printstacktrace (); <br/>}< br/>}
Obtain the list of running processes:
Public void getrunningprocesslist () {<br/> imagebutton ivicon; <br/> activitymanager AM = (activitymanager) getsystemservice (activity_service); <br/> List <activitymanager. runningappprocessinfo> List = aM. getrunningappprocesses (); <br/> packagemanager PM = This. getapplicationcontext (). getpackagemanager (); <br/> lltaskbar. removeallviews (); <br/> for (activitymanager. runningappprocessinfo Pi: List) {<br/> If (PM. getlaunchintentforpackage (PI. processname )! = NULL) {<br/> try {<br/> applicationinfo AI = PM. getapplicationinfo (Pi. processname, <br/> packagemanager. get_meta_data); <br/> If (Ai! = NULL) {<br/> ivicon = new imagebutton (this); <br/> ivicon. setimagedrawable (AI. loadicon (PM); <br/> ivicon. setfocusable (true); <br/> ivicon. setclickable (true); <br/> ivicon. setenabled (true); </P> <p> ivicon. setscaletype (scaletype. center); </P> <p> ivicon. setlayoutparams (New linearlayout. layoutparams (120,120); <br/> lltaskbar. addview (ivicon); <br/>}< br/>} catch (namenotfoundexception e) {<br/> E. printstacktrace (); <br/>}< br/>}