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=;i<process.size (); i++) {
activitymanager.runningappprocessinfo ar = process.get (i);
String packagename = ar.processname;
PackageName = Packagename.split (":") [];
Important level is greater than, and untrusted background will be killed
if (ar.importance> &&! 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_; 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/;
} 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.
Windowmanager.layoutparams This class is used to provide the parameters required for a suspended window, with several variables that are often used:
Type values are used to determine the types of suspension windows, typically set to 2002, above all applications, but under the status bar.
The flags value is used to determine the behavior of the suspension window, such as not focusing, modeless dialog boxes, and so on, so that you can view the document.
The gravity value is used to determine the alignment of the suspension window, generally set to the upper-left corner alignment, so that when the suspension window is dragged to facilitate the calculation of coordinates.
x value is used to determine the position of the suspension window, if you want to move the suspension window horizontally, you need to change this value.
The Y value is used to determine the position of the suspension window, and if you want to move the suspension window vertically, you need to change this value.
The width value is used to specify how wide the suspension window is.
The height value is used to specify the elevation of the suspension window.