Example usage for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_MODERATE

List of usage examples for android.content ComponentCallbacks2 TRIM_MEMORY_RUNNING_MODERATE

Introduction

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

Prototype

int TRIM_MEMORY_RUNNING_MODERATE

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

Click Source Link

Document

Level for #onTrimMemory(int) : the process is not an expendable background process, but the device is running moderately low on memory.

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:/*from ww  w. j a  v a 2  s.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);
            }/*from ww w .  j a v  a 2  s.  c o  m*/
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            imageLoader.onLowMemory(0.25f);
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
            imageLoader.onLowMemory(0.75f);
        }
    }
}