Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions library/src/main/java/com/bumptech/glide/RequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.manager.ConnectivityMonitor;
import com.bumptech.glide.manager.ConnectivityMonitorFactory;
Expand All @@ -28,7 +26,6 @@
import com.bumptech.glide.manager.RequestManagerTreeNode;
import com.bumptech.glide.manager.RequestTracker;
import com.bumptech.glide.manager.TargetTracker;
import com.bumptech.glide.request.BaseRequestOptions;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
Expand Down Expand Up @@ -93,7 +90,7 @@ public void run() {
@GuardedBy("this")
private RequestOptions requestOptions;

private boolean pauseAllRequestsOnTrimMemoryModerate;
private boolean pauseAllRequestsOnTrimMemoryUiHidden;

private boolean clearOnStop;

Expand Down Expand Up @@ -240,10 +237,10 @@ public RequestManager addDefaultRequestListener(RequestListener<Object> requestL

/**
* If {@code true} then clear all in-progress and completed requests when the platform sends
* {@code onTrimMemory} with level = {@code TRIM_MEMORY_MODERATE}.
* {@code onTrimMemory} with level >= {@code TRIM_MEMORY_UI_HIDDEN}.
*/
public void setPauseAllRequestsOnTrimMemoryModerate(boolean pauseAllOnTrim) {
pauseAllRequestsOnTrimMemoryModerate = pauseAllOnTrim;
pauseAllRequestsOnTrimMemoryUiHidden = pauseAllOnTrim;
}

/**
Expand Down Expand Up @@ -708,8 +705,15 @@ public synchronized String toString() {

@Override
public void onTrimMemory(int level) {
if (level == TRIM_MEMORY_MODERATE && pauseAllRequestsOnTrimMemoryModerate) {
pauseAllRequestsRecursive();
if (pauseAllRequestsOnTrimMemoryUiHidden) {
// On Android 14+ (API 34+), fine-grained trim levels like TRIM_MEMORY_MODERATE are
// deprecated.
// The primary signals indicating the app is not in the foreground are
// TRIM_MEMORY_UI_HIDDEN and higher. We should pause requests when the UI is hidden
// to save resources, in line with the original intent of pausing on memory pressure.
if (level >= TRIM_MEMORY_UI_HIDDEN) {
pauseAllRequestsRecursive();
}
}
}

Expand Down
Loading