美文网首页
Android清理后台进程

Android清理后台进程

作者: timmy_tan | 来源:发表于2016-12-27 16:15 被阅读355次
     /**
        *
        *   add timmy 20161220
        *   clean memory thread
        */
         Runnable runnable = new Runnable() {
    
            @Override
            public void run() {
                if(mActivityManager==null){
                    mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
                }
                List<ActivityManager.RunningAppProcessInfo> list = mActivityManager
                        .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_FOREGROUND) {
                          // 清理后台进程
                            for (int j = 0; j < pkgList.length; j++) {
                                String pkg = pkgList[j];
                                if(pkg.matches("com.android.*")){
                                    Log.d(TAG,"not clean is system android pid pkg= " +pkg);
                                }else{
                                    Log.d(TAG,"auto clean apk pkg= " + pkg);
                                    mActivityManager.forceStopPackage(pkgList[j]);
                                }    
                            }
                        }
                    }
                }
            }
        };
    

    相关文章

      网友评论

          本文标题:Android清理后台进程

          本文链接:https://www.haomeiwen.com/subject/qfkevttx.html