本文整理匯總了Java中android.app.ActivityManager.getProcessMemoryInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityManager.getProcessMemoryInfo方法的具體用法?Java ActivityManager.getProcessMemoryInfo怎麽用?Java ActivityManager.getProcessMemoryInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.getProcessMemoryInfo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPssForService
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* Get the PSS used by the process hosting a service.
*
* @param packageName Package name of the service to search for.
* @return the PSS in kB of the process hosting a service, or INVALID_PSS.
*/
@VisibleForTesting
static int getPssForService(ComponentName componentName) {
if (componentName == null) return INVALID_PSS;
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services =
activityManager.getRunningServices(1000);
if (services == null) return INVALID_PSS;
int pid = -1;
for (ActivityManager.RunningServiceInfo info : services) {
if (componentName.equals(info.service)) {
pid = info.pid;
break;
}
}
if (pid == -1) return INVALID_PSS;
Debug.MemoryInfo infos[] = activityManager.getProcessMemoryInfo(new int[] {pid});
if (infos == null || infos.length == 0) return INVALID_PSS;
return infos[0].getTotalPss();
}