Code example for ActivityManager

Methods: getProcessMemoryInfo

0
    private static MemoryInfo getCurrentAppMemory(Context context)
    { 
        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        int[] pids = new int[1];
        pids[0] = android.os.Process.myPid();
        MemoryInfo[] mis = am.getProcessMemoryInfo(pids);
        return mis[0];
    } 
    public static String getMemoryInfo(Context context)
    { 
        MemoryInfo mi = getCurrentAppMemory(context);
        return String.format("%d KB %d KB %d KB", mi.getTotalPss(), mi.getTotalSharedDirty(), mi.getTotalPrivateDirty());
    } 
    public static int getConsumedMemory(Context context)
    { 
        return getCurrentAppMemory(context).getTotalPss();
    } 
 
} 
Experience pair programming with AI  Get Codota for Java