Code example for ActivityManager

Methods: getMemoryClass

0
    storage = new AndroidStorage(activity);
 
    assetManager.assets = activity.getAssets();
    ActivityManager activityManager = (ActivityManager) activity.getApplication().getSystemService(
        Activity.ACTIVITY_SERVICE);
    int memoryClass = activityManager.getMemoryClass();
 
    // For low memory devices (like the HTC Magic), prefer 16-bit bitmaps 
    preferredBitmapConfig = memoryClass <= 16 ? Bitmap.Config.ARGB_4444 : mapDisplayPixelFormat();
  } 
 
  /** 
   * Determines the most performant pixel format for the active display. 
   */ 
  private Config mapDisplayPixelFormat() {
    int format = activity.getWindowManager().getDefaultDisplay().getPixelFormat();
 
    if (format == PixelFormat.RGBA_8888 || format == PixelFormat.RGBX_8888)
      return Bitmap.Config.ARGB_8888;
    return Bitmap.Config.ARGB_4444;
  }