Layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <ButtonAndroid:id= "@+id/updatebtn"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Update Processinfos" /> <TextViewAndroid:id= "@+id/time"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:textsize= "16SP"Android:textstyle= "Bold" /> <ScrollViewAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <TextViewAndroid:id= "@+id/text"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:textsize= "16SP"android:padding= "5DP"/> </ScrollView></LinearLayout>
Code
Public classHelloprocessactivityextendsactivity{PrivateTextView Mtextview =NULL; PrivateTextView MTime =NULL; PrivateButton Mbutton =NULL; PrivateString MText = ""; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_hello_process); Mtextview=(TextView) Findviewbyid (R.id.text); MTime=(TextView) Findviewbyid (r.id.time); Mbutton=(Button) Findviewbyid (R.ID.UPDATEBTN); Mbutton.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {updateprocessinfo (); } }); } Private voidUpdateprocessinfo () {MText= ""; Mtextview.settext (MText); //Get ActivitymanagerActivitymanager Activitymanager = (Activitymanager) This. Getsystemservice (Context.activity_service); //Update TimeUpdatetimeinfo (); //Get process information ***************************************************list<runningappprocessinfo> infos =Activitymanager. getrunningappprocesses (); for(Runningappprocessinfo info:infos) {String name=Info.processname; MText=Mtextview.gettext (). toString (); MText+ = name + "\ n"; Mtextview.settext (MText); } } Private voidUpdatetimeinfo () {SimpleDateFormat DF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//Set Date formatString time = Df.format (NewDate ()); System.out.println (time);//new Date () to get the current system timeMtime.settext (time); }}I'm the dividing line of the king of the land Tiger.
Reference: http://www.cnblogs.com/mengdd/p/3213378.html
Android--View all the processes on your phone