Today there is nothing to write a clear memory of the small things, similar to 360, suspended on the desktop, click to clear the background unwanted program, The removal of the background program is done by invoking the Activitymanger.killbackgroundprocesses method, which has a bad place, that is, the high application of the importance level setting cannot kill. The key code is shown below
Activitymanager Mactivitymanager = Mymanager.getactivitymanager (mcontext);
list<activitymanager.runningappprocessinfo> process = Mactivitymanager.getrunningappprocesses ();
for (int i=0;i<process.size (); i++) {
activitymanager.runningappprocessinfo ar = process.get (i);
String packagename = ar.processname;
PackageName = Packagename.split (":") [0];
The important level is greater than 200, and untrusted backgrounds will be killed
if (ar.importance>100 &&! Mymanager.istrust (PackageName)) {
Mymanager.getactivitymanager (mcontext). Killbackgroundprocesses ( PackageName);
}
There is also a part of the function, desktop suspension, this feature is added to the desktop through the Windowmanger object, the key code is as follows
WindowManager WindowManager = Getwindowmanager (context);
int screenwidth = Windowmanager.getdefaultdisplay (). GetWidth ();
int screenheight = Windowmanager.getdefaultdisplay (). GetHeight ();
if (msmallfloatwin==null) {Msmallfloatwin = new Smallfloatwin (context);
if (Smallwindowparams = = null) {smallwindowparams = new layoutparams ();
Smallwindowparams.type = Layoutparams.type_phone;
Smallwindowparams.format = pixelformat.rgba_8888; Smallwindowparams.flags = Layoutparams.flag_not_touch_modal |
layoutparams.flag_not_focusable; smallwindowparams.gravity = Gravity.left |
Gravity.top;
Smallwindowparams.width = Smallfloatwin.viewwidth;
Smallwindowparams.height = Smallfloatwin.viewheight;
Smallwindowparams.x = ScreenWidth;
Smallwindowparams.y = SCREENHEIGHT/2;
} msmallfloatwin.setparams (Smallwindowparams);
Windowmanager.addview (Msmallfloatwin, smallwindowparams);
}
Where Msmallfloatwin is the view object to be suspended.
PostScript: This little Thing kill the background program effect is not good, there is a way of thinking through the authority to execute the ADB command to the background program.
Attached source code click to download