John John
John John

Reputation: 165

how can I print the amount of memory that each task uses in Android

I save all the tasks in the activity manager by using this code

List<ActivityManager.RunningAppProcessInfo> list = am.getRunningAppProcesses();

now, I can get some information from this list like for example the pid of each task etc

but how can I find out how much memory each tasks uses? is it possible to do so from having obtained the above list?

thanks in advance

Upvotes: 1

Views: 266

Answers (1)

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

Use ActovityManager.getProcessMemoryInfo() and iterate the array.

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo info : activityManager.getRunningAppProcesses()) {
            Debug.MemoryInfo[] memInfo = activityManager.getProcessMemoryInfo(new int[]{info.pid});
            for (Debug.MemoryInfo memoryInfo : memInfo) {
                //
            }
        }

Upvotes: 1

Related Questions