check Memory via Runtime - Android android.os

Android examples for android.os:Memory

Description

check Memory via Runtime

Demo Code

import android.os.SystemClock;

public class Main {

  public static boolean checkMemory(long size) {
    Runtime runtime = Runtime.getRuntime();

    long freeMemory = runtime.freeMemory();
    if (size * 2 < freeMemory) {
      return true;
    } else {//w  ww  .ja  v  a  2 s .  co m
      System.gc();
    }
    SystemClock.sleep(500);
    if (size * 2 < freeMemory) {
      return true;
    } else {
      return false;
    }
  }

}

Related Tutorials