clean Memory - Android Hardware

Android examples for Hardware:Memory

Description

clean Memory

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;
import java.util.List;

public class Main {
    public static void cleanMemory(Context context) {
        ActivityManager activityManger = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> list = activityManger
                .getRunningAppProcesses();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                ActivityManager.RunningAppProcessInfo apinfo = list.get(i);
                String[] pkgList = apinfo.pkgList;
                if (apinfo.importance > ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE) {
                    for (int j = 0; j < pkgList.length; j++) {
                        activityManger.killBackgroundProcesses(pkgList[j]);
                    }//from   ww  w  .ja v a2s  . co m
                }
            }
        }
    }
}

Related Tutorials