當前位置: 首頁>>代碼示例>>Java>>正文


Java RunningAppProcessInfo.IMPORTANCE_VISIBLE屬性代碼示例

本文整理匯總了Java中android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java RunningAppProcessInfo.IMPORTANCE_VISIBLE屬性的具體用法?Java RunningAppProcessInfo.IMPORTANCE_VISIBLE怎麽用?Java RunningAppProcessInfo.IMPORTANCE_VISIBLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.app.ActivityManager.RunningAppProcessInfo的用法示例。


在下文中一共展示了RunningAppProcessInfo.IMPORTANCE_VISIBLE屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cleanMemory

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");
}
 
開發者ID:hubcarl,項目名稱:mobile-manager-tool,代碼行數:25,代碼來源:StorageUtil.java

示例2: isActivityForeground

/**
 * check FM is foreground or background
 */
public boolean isActivityForeground() {
    boolean isForeground = true;
    List<RunningAppProcessInfo> appProcessInfos = mActivityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo appProcessInfo : appProcessInfos) {
        if (appProcessInfo.processName.equals(mContext.getPackageName())) {
            int importance = appProcessInfo.importance;
            Log.d(TAG, "isActivityForeground importance:" + importance);
            if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND ||
                    importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                Log.d(TAG, "isActivityForeground is foreground");
                isForeground = true;
            } else {
                Log.d(TAG, "isActivityForeground is background");
                isForeground = false;
            }
            break;
        }
    }
    Log.d(TAG, "isActivityForeground return " + isForeground);
    return isForeground;
}
 
開發者ID:hyperion70,項目名稱:android_device_MTS_x2605,代碼行數:24,代碼來源:FmRadioService.java

示例3: doInBackground

@Override
protected Void doInBackground(Void... params) {
    ActivityManager activityManager=(ActivityManager)mainActivity.getSystemService("activity");
    List<RunningAppProcessInfo> procInfo=activityManager.getRunningAppProcesses();
    for (int i=0;i<procInfo.size();i++)
    {
        RunningAppProcessInfo process=procInfo.get(i);
        int importance=process.importance;
        String name=process.processName;
        if(!name.equals("com.dev.system.monitor")&&
                !name.contains("launcher")&&
                !name.contains("googlequicksearchbox")&&
                importance>RunningAppProcessInfo.IMPORTANCE_VISIBLE)
            activityManager.killBackgroundProcesses(name);
    }
    return null;
}
 
開發者ID:Daniele-Comi,項目名稱:System-Monitor,代碼行數:17,代碼來源:RAMManagement.java

示例4: getImportance

private String getImportance( RunningAppProcessInfo proc )
{
	String impt = "Empty"; //$NON-NLS-1$

	switch ( proc.importance )
	{
		case RunningAppProcessInfo.IMPORTANCE_BACKGROUND :
			impt = "Background"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_FOREGROUND :
			impt = "Foreground"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE :
			impt = "Perceptible"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_SERVICE :
			impt = "Service"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_VISIBLE :
			impt = "Visible"; //$NON-NLS-1$
			break;
	}

	return impt;
}
 
開發者ID:qauck,項目名稱:qsysinfo,代碼行數:25,代碼來源:SysInfoManager.java

示例5: clearMemory

private void clearMemory() {
       ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);  
       List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();  
       //List<ActivityManager.RunningServiceInfo> serviceInfos = am.getRunningServices(100);  

       long beforeMem = MyWindowManager.getAvailableMemory();  
       String TAG = "";
       Log.d(TAG, "-----------before memory info : " + beforeMem);  
       int count = 0;  
       if (infoList != null) {  
           for (int i = 0; i < infoList.size(); ++i) {  
               RunningAppProcessInfo appProcessInfo = infoList.get(i);  
               Log.d(TAG, "process name : " + appProcessInfo.processName);  
               //importance �ý��̵���Ҫ�̶�  ��Ϊ����������ֵԽ�;�Խ��Ҫ��  
               Log.d(TAG, "importance : " + appProcessInfo.importance);  

               // һ����ֵ����RunningAppProcessInfo.IMPORTANCE_SERVICE�Ľ��̶���ʱ��û�û��߿ս�����  
               // һ����ֵ����RunningAppProcessInfo.IMPORTANCE_VISIBLE�Ľ��̶��Ƿǿɼ����̣�Ҳ�����ں�̨������  
               if (appProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {  
                   String[] pkgList = appProcessInfo.pkgList;  
                   for (int j = 0; j < pkgList.length; ++j) {//pkgList �õ��ý��������еİ���  
                       Log.d(TAG, "It will be killed, package name : " + pkgList[j]);  
                       if (!"com.lazy.floatwindowdemo".equals(pkgList[j])) {
                       	am.killBackgroundProcesses(pkgList[j]);  
                           count++;  
					}
                   }  
               }  
           }  
       }

       long afterMem = MyWindowManager.getAvailableMemory();  
       Log.d(TAG, "----------- after memory info : " + afterMem);  
       Toast.makeText(context, "clear " + count + " process, "  
                   + (afterMem - beforeMem)/1024 + "M", Toast.LENGTH_LONG).show();
}
 
開發者ID:lazyprogramer,項目名稱:FloatWindowKillProcess,代碼行數:36,代碼來源:FloatWindowBig.java

示例6: isAppOnForeground

/**
 * 判斷程序是否在前台
 *
 * @return true 在前台; false 在後台
 */
private boolean isAppOnForeground() {
    if (!isSpecialSystem) {
        boolean isspecial = true;
        String packageName = context.getPackageName();
        List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
        if (appProcesses == null)
            return false;
        for (RunningAppProcessInfo appProcess : appProcesses) {
            if (appProcess.processName.equals(packageName)) {
                if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                    return true;
                }
                if (keyguardManager.inKeyguardRestrictedInputMode()) return true;
            }
            if (isspecial) {
                if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    isspecial = false;
                }
            }
        }
        if (isspecial) {
            isSpecialSystem = true;
            return !isApplicationBroughtToBackgroundByTask();
        }
        return false;
    } else {
        return !isApplicationBroughtToBackgroundByTask();
    }
}
 
開發者ID:ownwell,項目名稱:zztinews,代碼行數:34,代碼來源:AppRunningInBackground.java

示例7: isSPARunnung

public boolean isSPARunnung() {
	ActivityManager activityManager = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
	List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
	for( int i = 0; i < procInfos.size(); i++ ) {
		if( procInfos.get( i ).processName.equals( Constants.SPA_PACKAGE_NAME ) ) {
			if( procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE ) {
				return true;
			} else if( procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND && procInfos.get( i ).lru == Constants.BG_IMPORTANCE_LIVE ) {
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:SilentCircle,項目名稱:silent-text-android,代碼行數:14,代碼來源:ConversationListActivity.java

示例8: runProcessGC

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) {
            //前台進程。
        }
    }

}
 
開發者ID:amikey,項目名稱:DroidPlugin,代碼行數:49,代碼來源:MyActivityManagerService.java

示例9: releaseRam

public static void releaseRam(Context context) {
	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

	// To change body of implemented methods use File | Settings | File Templates.
	List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();
	List<RunningServiceInfo> serviceInfos = am.getRunningServices(100);

	long beforeMem = getAvailMemory(context);
	Log.i(TAG, "Before release, avail memory: " + beforeMem);

	int count = 0;

	for (int i = 0; i < infoList.size(); ++i) {
		RunningAppProcessInfo appProcessInfo = infoList.get(i);

		Log.d(TAG, "Process name: " + appProcessInfo.processName);

		// importance 該進程的重要程度 分為幾個級別,數值越低就越重要。
		Log.d(TAG, "Importance: " + appProcessInfo.importance);

		// 一般數值大於RunningAppProcessInfo.IMPORTANCE_SERVICE 的進程都長時間沒用或者空進程了
		// 一般數值大於RunningAppProcessInfo.IMPORTANCE_VISIBLE 的進程都是非可見進程, 也就是在後台運行著
		// 我這裏選擇閾值是IMPORTANCE_VISIBLE級別的,也就是非可見的後台進程和服務會被殺掉(一些係統進程肯定除外)。
		// 清理的效果跟金山清理大師和360桌麵的一鍵清理效果差不多。
		// 如果不想殺的太凶,可以選擇IMPORTANCE_SERVICE級別,殺掉那些長時間沒用或者空進程了,
		// 這個級別的清理力度不夠大,達不到金山清理大師的效果。
		if (appProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
			String[] pkgList = appProcessInfo.pkgList;

			int length = pkgList.length;
			for (int j = 0; j < length; ++j) {// pkgList 得到該進程下運行的包名
				String packageName = pkgList[j];

				if (packageName.equals(context.getPackageName())) {
					continue;
				}

				Log.d(TAG, packageName + " will be killed.");

				am.killBackgroundProcesses(packageName);

				count++;
			}
		}
	}

	long afterMem = getAvailMemory(context);
	Log.i(TAG, "After release, avail memory: " + afterMem);

	Log.w(TAG, "Clear " + count + " processes, " + (afterMem - beforeMem) + "M released");
}
 
開發者ID:imknown,項目名稱:IMKBaseFrameworkLibrary,代碼行數:51,代碼來源:DeviceUtil.java


注:本文中的android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。