get Minimum Heap Size from dalvik.system.VM Runtime - Android Android OS

Android examples for Android OS:Heap

Description

get Minimum Heap Size from dalvik.system.VM Runtime

Demo Code


//package com.java2s;
import java.lang.reflect.Method;

public class Main {
    public static long getMinimumHeapSize() {
        try {//from  ww  w  .j  av a2s . c  o  m
            Class VMRuntimeClass = Class.forName("dalvik.system.VMRuntime");
            Method getRuntimeMethod = VMRuntimeClass.getMethod(
                    "getRuntime", new Class[0]);
            Class[] arrayOfClass = new Class[1];
            arrayOfClass[0] = Long.TYPE;
            Method getMinimumHeapSizeMethod = VMRuntimeClass.getMethod(
                    "getMinimumHeapSize", new Class[0]);
            Object runtimeObject = getRuntimeMethod.invoke(null,
                    new Object[0]);
            Long ret = (Long) getMinimumHeapSizeMethod.invoke(
                    runtimeObject, new Object[0]);
            android.util.Log.e("BAIDUMAP_PERFM",
                    "getMinimumHeapSizeMethod:" + ret.longValue());
            return ret.longValue();
        } catch (Throwable localThrowable) {
            localThrowable.printStackTrace();
        }
        return 0;
    }
}

Related Tutorials