Android獲取應用所占內存大小

	private void getRunningAppProcessInfo() {
		mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

		//獲得系統裡正在運行的所有進程
		List runningAppProcessesList = mActivityManager.getRunningAppProcesses();

		for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcessesList) {
			// 進程ID號
			int pid = runningAppProcessInfo.pid;
			// 用戶ID
			int uid = runningAppProcessInfo.uid;
			// 進程名
			String processName = runningAppProcessInfo.processName;
			// 占用的內存
			int[] pids = new int[] {pid};
			Debug.MemoryInfo[] memoryInfo = mActivityManager.getProcessMemoryInfo(pids);
			int memorySize = memoryInfo[0].dalvikPrivateDirty;

			System.out.println("processName="+processName+",pid="+pid+",uid="+uid+",memorySize="+memorySize+"kb");
		}
	}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *