문제

I was wondering how I could get the amount of RAM usage of a given application or a package name that is installed in the android device. I so far went on with a package manager and feeding it with the package name I want. However, there is no method that I could use to get it out. I don't know what to do after this. Please some one help me on getting the RAM amount that a particular application is using currently.

도움이 되었습니까?

해결책

this function help you :

public static void logHeap(Class<?> clazz) {
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));        
        Double available = new Double(Debug.getNativeHeapSize()/1048576.0);
        Double free = new Double(Debug.getNativeHeapFreeSize()/1048576.0);
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("memory-usage", "===================================================================================================");
        Log.d("memory-usage", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.myapp.android.","") + "]");
        Log.d("memory-usage", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");

        System.gc();
        System.gc();
    }

다른 팁

You can use adb tools to get memory information that app consume

adb shell dumpsys meminfo

can take this output to textfile by adb shell dumpsys meminfo > meminfo.txt

Here previous good explanation of this in

How do I discover memory usage of my application in Android?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top