Back to project page cube-sdk.
The source code is released under:
Apache License
If you think the Android project cube-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package in.srain.cube.util; /* w w w . ja va 2 s.c o m*/ import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.MemoryInfo; import android.content.Context; import android.util.Log; import java.util.Timer; import java.util.TimerTask; public class SystemWatcher { private static SystemWatcher sInstance = new SystemWatcher(); private Context mContext; private SystemWatcher() { } public static SystemWatcher getInstance() { return sInstance; } public static void init(Context context) { sInstance.mContext = context; } private Timer mTimer; private TimerTask mTimerTask; public void run() { mTimerTask = new TimerTask() { @Override public void run() { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); Runtime runtime = Runtime.getRuntime(); String s = String.format("free:%s%% %sKB total:%sKB max:%sKB ", runtime.freeMemory() * 100f / runtime.totalMemory(), runtime.freeMemory(), runtime.totalMemory() / 1024, runtime.maxMemory() / 1024); // s += String.format("native: free:%sKB total:%sKB max:%sKB", android.os.Debug.getNativeHeapFreeSize() / 1024, android.os.Debug.getNativeHeapAllocatedSize() / 1024, // android.os.Debug.getNativeHeapSize() / 1024); // s += String.format("| availMem:%sKB", mi.availMem / 1024); Log.d("memory", s); } }; mTimer = new Timer(); mTimer.schedule(mTimerTask, 1000, 1000); } }