Java Code Examples for android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_VISIBLE
The following examples show how to use
android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_VISIBLE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageUtil.java From mobile-manager-tool with MIT License | 6 votes |
public static void cleanMemory(Context context){ System.out.println("---> 清理前可用内存:"+getAvailMemory(context)+"MB"); ActivityManager activityManager=(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses(); if (processList != null) { for (int i = 0; i < processList.size(); ++i) { RunningAppProcessInfo runningAppProcessInfo= processList.get(i); // 一般数值大于RunningAppProcessInfo.IMPORTANCE_SERVICE // 的进程即为长时间未使用进程或者空进程 // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE // 的进程都是非可见进程,即在后台运行 if (runningAppProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) { String[] pkgList = runningAppProcessInfo.pkgList; for (int j = 0; j < pkgList.length; ++j) { System.out.println("===> 正在清理:"+pkgList[j]); activityManager.killBackgroundProcesses(pkgList[j]); } } } } System.out.println("---> 清理后可用内存:"+getAvailMemory(context)+"MB"); }
Example 2
Source File: ProcessFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
private void bind(final int position) { final ProcessInfo pi = lpinfo.get(position); cbx.setTag(pi); more.setTag(pi); name.setText(pi.label); attr.setText(pi.packageName); items.setText(Util.nf.format(pi.size) + " B"); int importance = pi.status; if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { type.setText("Foreground"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE) { type.setText("Foreground Service"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { type.setText("Background"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) { type.setText("Visible"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) { type.setText("Perceptible"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) { type.setText("Service"); } else if (importance == 150) {//}RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING) { type.setText("Sleep"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_GONE) { type.setText("Gone"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) { type.setText("Can't save state"); } else if (importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) { type.setText("Empty"); } try { image.setImageDrawable(pk.getApplicationIcon(pi.packageName)); } catch (NameNotFoundException e) { image.setImageResource(R.drawable.ic_doc_apk); } final boolean checked = selectedInList1.contains(pi.packageName); if (checked) { ll.setBackgroundColor(Constants.IN_DATA_SOURCE_2); cbx.setSelected(true); cbx.setImageResource(R.drawable.ic_accept); } else if (selectedInList1.size() > 0) { ll.setBackgroundColor(Constants.BASE_BACKGROUND); cbx.setSelected(false); cbx.setImageResource(R.drawable.ready); } else { ll.setBackgroundResource(R.drawable.ripple); cbx.setSelected(false); cbx.setImageResource(R.drawable.dot); } }
Example 3
Source File: MyActivityManagerService.java From DroidPlugin with GNU Lesser General Public License v3.0 | 4 votes |
private void runProcessGC() { if (mHostContext == null) { return; } ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return; } List<RunningAppProcessInfo> infos = am.getRunningAppProcesses(); List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>(); if (infos == null || infos.size() < 0) { return; } List<String> pns = mStaticProcessList.getOtherProcessNames(); pns.add(mHostContext.getPackageName()); for (RunningAppProcessInfo info : infos) { if (info.uid == android.os.Process.myUid() && info.pid != android.os.Process.myPid() && !pns.contains(info.processName) && mRunningProcessList.isPlugin(info.pid) && !mRunningProcessList.isPersistentApplication(info.pid) /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/) { myInfos.add(info); } } Collections.sort(myInfos, sProcessComparator); for (RunningAppProcessInfo myInfo : myInfos) { if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { doGc(myInfo); } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) { doGc(myInfo); } /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) { //杀死进程,不能保存状态。但是关我什么事? }*/ else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) { //杀死进程 } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) { //看得见 } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { //前台进程。 } } }