2

I wanted to use the helper method isLowRamDevice for my app, which streams videos. As I support devices down do API level 15, I had to use ActivityManagerCompat.isLowRamDevice(). I was really confused, that it always returned false, even if I use really old devices. Then I checked the method itself and saw this:

    public static boolean isLowRamDevice(@NonNull ActivityManager am) {
        if (Build.VERSION.SDK_INT >= 19) {
            return ActivityManagerCompatKitKat.isLowRamDevice(am);
        }
        return false;
    }

So no wonder it always returns false on my Android 4.0.4 device. But for me this makes absolutely no sense. Or am I missing something?

JensJensen
  • 1,017
  • 1
  • 12
  • 25

1 Answers1

6

So no wonder it always returns false

It does not always return false.

On devices running Android 4.3 or older, it will always return false. That is because the system flag for being a low-RAM device did not exist back then.

On devices running Android 4.4 or higher, it will return the value of the system flag for whether this is a low-RAM device or not:

/**
 * Returns true if this is a low-RAM device.  Exactly whether a device is low-RAM
 * is ultimately up to the device configuration, but currently it generally means
 * something in the class of a 512MB device with about a 800x480 or less screen.
 * This is mostly intended to be used by apps to determine whether they should turn
 * off certain features that require more RAM.
 */
public boolean isLowRamDevice() {
    return isLowRamDeviceStatic();
}

/** @hide */
public static boolean isLowRamDeviceStatic() {
    return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
}

(from the ActivityManager source code)

AFAIK, low-RAM devices mostly will be Android One devices. Depending upon where you get your devices, you may not encounter one of those.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sure, but devices running Android 4.3 or older are more likely lowRamDevices. So why did they make this method available for older devices via support lib? This makes absolutely no sense. – JensJensen Aug 19 '16 at 12:24
  • @JensJensen: "devices running Android 4.3 or older are more likely lowRamDevices" -- not necessarily by Google's definition of low RAM devices. "So why did they make this method available for older devices via support lib?" -- pretty much all classes ending in `...Compat` work this way. They call through to the real implementation on compatible devices and return some stub on older devices. Sometimes, the stub is more sophisticated. In this case, I agree that they should have derived a value based on the actual device RAM. – CommonsWare Aug 19 '16 at 12:41
  • The implementation is consistent with other support libs. It sounds like you want to treat old devices as low-ram, so I would say you're better off abstracting the call and checking API version in and the isLowRamDevice() flag together. – Travis Castillo Mar 01 '17 at 17:54
  • 1
    Fast forward to now, this is used for Android Go build. – Andrew T. Jul 29 '22 at 10:40