bumptech/glide · error · IllegalArgumentException
You must call this method on a background thread
Error message
You must call this method on a background thread
What it means
Thrown by Util.assertBackgroundThread() when the calling code is on the main (UI) thread. Some Glide internals and APIs (notably certain cache/disk operations and RequestBuilder.asDrawable().submit() style synchronous fetches run on background executors) require a background thread to avoid blocking the UI; calling them on the main thread is rejected.
Source
Thrown at library/src/main/java/com/bumptech/glide/util/Util.java:192
}
}
return mainThreadHandler;
}
/**
* Throws an {@link java.lang.IllegalArgumentException} if called on a thread other than the main
* thread.
*/
public static void assertMainThread() {
if (!isOnMainThread()) {
throw new IllegalArgumentException("You must call this method on the main thread");
}
}
/** Throws an {@link java.lang.IllegalArgumentException} if called on the main thread. */
public static void assertBackgroundThread() {
if (!isOnBackgroundThread()) {
throw new IllegalArgumentException("You must call this method on a background thread");
}
}
/** Returns {@code true} if called on the main thread, {@code false} otherwise. */
public static boolean isOnMainThread() {
return Looper.myLooper() == Looper.getMainLooper();
}
/** Returns {@code true} if called on a background thread, {@code false} otherwise. */
public static boolean isOnBackgroundThread() {
return !isOnMainThread();
}
/** Creates a {@link java.util.Queue} of the given size using Glide's preferred implementation. */
@NonNull
public static <T> Queue<T> createQueue(int size) {
return new ArrayDeque<>(size);
}View on GitHub (pinned to eb14a895d8)
Solutions
- Move the call off the main thread: withContext(Dispatchers.IO) { ... } or an AsyncTask/Executor
- For clearDiskCache specifically, run it on a background executor and post UI updates back
- For fetching an image synchronously, use submit().get() only on a background thread, or switch to an async into() with a Target
- Audit the stack trace to find the UI-thread caller of the background-only method
Example fix
// before
fun onClearCacheClicked() {
Glide.get(this).clearDiskCache() // throws: main thread
}
// after
fun onClearCacheClicked() {
lifecycleScope.launch(Dispatchers.IO) {
Glide.get(this@Activity).clearDiskCache()
}
} Defensive patterns
Strategy: validation
Validate before calling
fun isBackgroundThread(): Boolean =
Looper.myLooper() != Looper.getMainLooper()
if (isBackgroundThread()) {
Glide.get(ctx).clearDiskCache()
} else {
// move to a background executor
} Prevention
- Run clearDiskCache() and other background-only APIs on Dispatchers.IO / an Executor
- Never call submit().get() synchronous fetches on the main thread
- Audit onClick handlers for direct background-only Glide calls
When it happens
Trigger: Calling a Glide API marked as background-only from the UI thread directly; e.g. certain disk-cache methods, or synchronous submit().get() patterns; helper methods inside custom decoders/modules that assert background execution.
Common situations: Calling Glide's disk cache inspection APIs (e.g. Glide.get(ctx).clearDiskCache()) from an onClick handler; synchronous fetch via RequestBuilder.submit().get() on the main thread; custom logic invoking assertBackgroundThread-bearing utilities during bind.
Related errors
- You must call this method on the main thread
- You can't start or clear loads in RequestListener or Target
- You cannot start a load on a fragment before it is attached
- Unable to find GlideModule implementation
- Expected instanceof GlideModule, but found: {module}
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/e70170e56589d4d1.
Report an issue: GitHub.