Android obtains task and Process

Source: Internet
Author: User
Public class myactivitymanager extends expandablelistactivity {Private Static final string name = "name"; Private Static final string no_used = "no_used"; private string [] groups = {"showrecenttask ", "showrunningtasks", "clusters", "showrunningservices"}; private expandablelistadapter madapter; activitymanager Mam; packagemanager MPM; @ override public void oncreate (bundle savedins Tancestate) {super. oncreate (savedinstancestate); mam = (activitymanager) This. getsystemservice (context. activity_service); MPM = This. getpackagemanager (); List <Map <string, string> groupdata = new arraylist <Map <string, string> (); List <list <Map <string, string >>> childdata = new arraylist <list <Map <string, string >>> (); For (INT I = 0; I <groups. length; I ++) {if (I = 0) {showrecenttask ();} else If (I = 1) {showrunningtasks ();} else if (I = 2) {showrunningappprocesses ();} else {showrunningservices ();} Map <string, string> curgroupmap = new hashmap <string, string> (); groupdata. add (curgroupmap); curgroupmap. put (name, groups [I] + "(" + strchildren. size () + ")"); curgroupmap. put (no_used, ""); List <Map <string, string> Children = new arraylist <Map <string, string> (); For (Int J = 0; j <Strchildren. size (); j ++) {Map <string, string> curchildmap = new hashmap <string, string> (); children. add (curchildmap); curchildmap. put (name, strchildren. get (j); curchildmap. put (no_used, "");} childdata. add (children);} // set up our adapter madapter = new simpleexpandablelistadapter (this, groupdata, android. r. layout. simple_expandable_list_item_1, new string [] {name, no_used}, new int [] {android Oid. r. id. text1, android. r. id. text2}, childdata, android. r. layout. simple_list_item_1, new string [] {name, no_used}, new int [] {android. r. id. text1, android. r. id. text2}); setlistadapter (madapter);} public list <string> strchildren = new arraylist <string> (); // The most recent task, press the Home Key to view the public void showrecenttask () {list <recenttaskinfo> tasklist = mam. getrecenttasks (100, 0); strchildren. clear (); (Recenttaskinfo RRTI: tasklist) {resolveinfo rI = MPM. resolveactivity (RFC. baseintent, 0); If (Ri! = NULL) {log. E ("showrecenttask", "" + Ri. loadlabel (MPM); strchildren. add (Ri. loadlabel (MPM ). tostring () ;}}// public void showrunningtasks () {list <runningtaskinfo> tasklist = mam. getrunningtasks (100); strchildren. clear (); For (runningtaskinfo RTL: tasklist) {log. E ("showrunningtasks", "running task, numactivities =" + RTI. numactivities); log. E ("showrunningtasks", ", description =" + RTI. Description); log. E ("showrunningtasks", ", baseactivity =" + rrsps. baseactivity. getclassname (); log. E ("showrunningtasks", ", topactivity =" + RTI. topactivity. getclassname (); strchildren. add (rrps. baseactivity. getclassname () ;}// process in the running state as the app container. Public void showrunningappprocesses () {list <runningappprocessinfo> processlist = mam. getrunningappprocesses (); strchildren. clear (); For (runningappprocessinfo rapi: processlist) {log. E ("showrunningappprocesses", "" + rapi. processname); strchildren. add (rapi. processname) ;}// the running background service public void showrunningservices () {list <runningserviceinfo> rsilist = mam. getrunningservices (100); strchildren. clear (); For (runningserviceinfo RSI: rsilist) {log. E ("showrunningservices", "" + RSI. process); strchildren. add (RSI. process );}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.