Android realizes 360 desktop suspension scavenging memory _android

Source: Internet
Author: User

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

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.