{"record":{"id":"e4f319bf9d84d3df","repo":"bumptech/glide","slug":"you-cannot-start-a-load-for-a-destroyed-activity","errorCode":null,"errorMessage":"You cannot start a load for a destroyed activity","messagePattern":"You cannot start a load for a destroyed activity","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java","lineNumber":237,"sourceCode":"    tempViewToSupportFragment.clear();\n    return result;\n  }\n\n  @Nullable\n  private static Activity findActivity(@NonNull Context context) {\n    if (context instanceof Activity) {\n      return (Activity) context;\n    } else if (context instanceof ContextWrapper) {\n      return findActivity(((ContextWrapper) context).getBaseContext());\n    } else {\n      return null;\n    }\n  }\n\n  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)\n  private static void assertNotDestroyed(@NonNull Activity activity) {\n    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {\n      throw new IllegalArgumentException(\"You cannot start a load for a destroyed activity\");\n    }\n  }\n\n  /**\n   * @deprecated This is equivalent to calling {@link #get(Context)} with the application context.\n   *     Use androidx fragments instead: {@link Fragment}.\n   */\n  @Deprecated\n  @NonNull\n  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)\n  public RequestManager get(@NonNull android.app.Fragment fragment) {\n    if (fragment.getActivity() == null) {\n      throw new IllegalArgumentException(\n          \"You cannot start a load on a fragment before it is attached\");\n    }\n    return get(fragment.getActivity().getApplicationContext());\n  }\n","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java#L219-L255","documentation":"IllegalArgumentException thrown by RequestManagerRetriever.assertNotDestroyed() when the Activity passed to Glide.with(activity) reports isDestroyed()==true (API 17+). Loading into a destroyed activity would leak the request and crash on UI updates, so Glide rejects it up front.","triggerScenarios":"Calling Glide.with((FragmentActivity) activity) or Glide.with((Activity) activity) after Activity.isDestroyed() returns true. Happens in async callbacks (Handler posts, Retrofit responses, coroutines) that fire after the user navigated away.","commonSituations":"Network callbacks completing after the activity is finished. RecyclerView adapters loading images in onViewRecycled paths racing with activity destruction. Post-delayed runnables that outlive the activity.","solutions":["Check !isDestroyed() && !isFinishing() before issuing the load in callbacks.","Cancel pending loads in onDestroy() (Glide.with(this).clear(target)).","Use lifecycle-scoped coroutines/LiveData so callbacks don't fire after destroy.","For background-thread fetches, use Glide.with(applicationContext) so the request outlives the activity safely."],"exampleFix":"// before\napi.fetchImage(url, new Callback() {\n  public void onSuccess(Bitmap b) {\n    Glide.with(activity).load(url).into(img);\n  }\n});\n// after\napi.fetchImage(url, new Callback() {\n  public void onSuccess(Bitmap b) {\n    if (activity.isDestroyed() || activity.isFinishing()) return;\n    Glide.with(activity).load(url).into(img);\n  }\n});","handlingStrategy":"validation","validationCode":"// Guard async callbacks against a destroyed/finishing activity.\nActivity activity = weakActivity.get();\nif (activity == null || activity.isDestroyed() || activity.isFinishing()) {\n  return; // skip the load\n}\nGlide.with(activity).load(url).into(img);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check isDestroyed()/isFinishing() in any async image callback.","Cancel loads in onDestroy() via Glide.with(this).clear(target).","Use applicationContext for background fetches that may outlive the activity.","Scope coroutines/LiveData to the activity lifecycle."],"tags":["activity","lifecycle","requestmanager","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}