Example usage for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_CRITICAL

List of usage examples for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_CRITICAL

Introduction

In this page you can find the example usage for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_CRITICAL.

Prototype

int TRIM_MEMORY_RUNNING_CRITICAL

To view the source code for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_CRITICAL.

Click Source Link

Document

Level for #onTrimMemory(int) : the process is not an expendable background process, but the device is running extremely low on memory and is about to not be able to keep any background processes running.

Usage

From source file:Main.java

public static String getTrimLevelName(int level) {
    switch (level) {
    case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
        return "COMPLETE";
    case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
        return "MODERATE";
    case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
        return "BACKGROUND";
    case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
        return "UI_HIDDEN";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
        return "RUNNING_CRITICAL";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
        return "RUNNING_LOW";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
        return "RUNNING_MODERATE";
    default:// w  w w .j a va 2s .c  o  m
        return "UNKNOWN";
    }
}

From source file:github.popeen.dsub.service.DownloadService.java

@Override
public void onTrimMemory(int level) {
    ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(this);
    if (imageLoader != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        Log.i(TAG, "Memory Trim Level: " + level);
        if (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
            if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL) {
                imageLoader.onLowMemory(0.75f);
            } else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
                imageLoader.onLowMemory(0.50f);
            } else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE) {
                imageLoader.onLowMemory(0.25f);
            }/* w ww .  j  a  va2s  .co  m*/
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            imageLoader.onLowMemory(0.25f);
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
            imageLoader.onLowMemory(0.75f);
        }
    }
}