本文整理汇总了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();
}