<p dir="auto">MainActivity has below code for load GIF first time it's working if I restart application it gets a crash for loading gif.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ImageView imageViewGIF = navigationView.findViewById(R.id.imageViewGIF);
     Glide.with(this).asGif().load(R.drawable.gift_3).into(imageViewGIF);"><pre class="notranslate"><code class="notranslate">ImageView imageViewGIF = navigationView.findViewById(R.id.imageViewGIF);
     Glide.with(this).asGif().load(R.drawable.gift_3).into(imageViewGIF);
</code></pre></div>
<p dir="auto">but when I restart the app it gets  a crash for at loading of GIF<br>
```</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" Intent intent = new Intent(context, SplashActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |          Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();"><pre class="notranslate"><code class="notranslate"> Intent intent = new Intent(context, SplashActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |          Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="application get a crash with below log.

     ```
   FATAL EXCEPTION: main
     Process: com.app.package, PID: 19360
     java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
         at android_support.qc.b(RequestManagerRetriever.java:298)
         at android_support.qc.a(RequestManagerRetriever.java:123)
         at android_support.ji.a(Glide.java:589)"><pre class="notranslate"><code class="notranslate">application get a crash with below log.

     ```
   FATAL EXCEPTION: main
     Process: com.app.package, PID: 19360
     java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
         at android_support.qc.b(RequestManagerRetriever.java:298)
         at android_support.qc.a(RequestManagerRetriever.java:123)
         at android_support.ji.a(Glide.java:589)
</code></pre></div>
<p dir="auto">i have used<br>
<code class="notranslate"> </code>'com.github.bumptech.glide:glide:4.2.0'``<br>
<code class="notranslate">'com.github.bumptech.glide:glide:4.3.1'</code></p>
<p dir="auto">both versions have the same issue</p>
<p dir="auto"><strong>TLDR</strong>; Glide should just log and cancel the load instead of crashing when the activity is destoryed since there is no point in loading anything. The user of the library shouldn't have to explicitly handle this situation.</p>
<hr>
<p dir="auto"><strong>Glide Version/Integration library (if any)</strong>:  'com.github.bumptech.glide:glide:3.6.1'<br>
<strong>Device/Android Version</strong>: Any/Android 5.0+<br>
<strong>Issue details/Repro steps/Use case background</strong>:</p>
<p dir="auto">This issue is related to issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="42845070" data-permission-text="Title is private" data-url="https://github.com/bumptech/glide/issues/138" data-hovercard-type="issue" data-hovercard-url="/bumptech/glide/issues/138/hovercard" href="https://github.com/bumptech/glide/issues/138">#138</a>. When making a call on glide if the activity has been destroyed it will throw an IllegalArgumentException. The following code in the RequestManagerRetriever.java class is responsible:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void assertNotDestroyed(Activity activity) {
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR1 &amp;&amp; activity.isDestroyed()) {
        throw new IllegalArgumentException(&quot;You cannot start a load for a destroyed activity&quot;);
    }
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">TargetApi</span>(<span class="pl-smi">Build</span>.<span class="pl-c1">VERSION_CODES</span>.<span class="pl-c1">JELLY_BEAN_MR1</span>)
<span class="pl-k">private</span> <span class="pl-k">static</span> <span class="pl-smi">void</span> <span class="pl-s1">assertNotDestroyed</span>(<span class="pl-smi">Activity</span> <span class="pl-s1">activity</span>) {
    <span class="pl-k">if</span> (<span class="pl-smi">Build</span>.<span class="pl-c1">VERSION</span>.<span class="pl-c1">SDK_INT</span> &gt;= <span class="pl-smi">Build</span>.<span class="pl-c1">VERSION_CODES</span>.<span class="pl-c1">JELLY_BEAN_MR1</span> &amp;&amp; <span class="pl-s1">activity</span>.<span class="pl-en">isDestroyed</span>()) {
        <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-smi">IllegalArgumentException</span>(<span class="pl-s">"You cannot start a load for a destroyed activity"</span>);
    }
}</pre></div>
<p dir="auto">This is causing a crash in my crashlytics console for a small percentage of my users. There is likely some kind of timing issue where the user hits home as they are scrolling a big list and the activity is cleaned up which results in this crash. I could fix this issue by wrapping glide and running this code myself and simply not calling glide in this situation. However I believe this is the wrong approach, the library shouldn't be crashing in this situation and instead should log and do nothing.</p>
<p dir="auto">If the activity is destroyed then the view that is being displayed which the image is being displayed is not visible and as a result no exception should be thrown. Instead glide should log and simply not show the image. Users of the library should not have to explicitly handle situations like these, it makes more sense to just handle it in the library.</p>
<p dir="auto"><strong>Glide load line</strong>:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with(context).load(url).bitmapTransform(new GrayscaleTransformation(getContext())).into(imageView);"><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-s1">context</span>).<span class="pl-en">load</span>(<span class="pl-s1">url</span>).<span class="pl-en">bitmapTransform</span>(<span class="pl-k">new</span> <span class="pl-smi">GrayscaleTransformation</span>(<span class="pl-en">getContext</span>())).<span class="pl-en">into</span>(<span class="pl-s1">imageView</span>);</pre></div>
<p dir="auto"><strong>Layout XML</strong>: not relevant</p>
<p dir="auto"><strong>Stack trace / LogCat</strong>:</p>
<div class="highlight highlight-source-ruby notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Fatal Exception: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:134)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:102)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:87)
       at com.bumptech.glide.Glide.with(Glide.java:620)
       at com.myapp.myapp$24.run(MyAppClass.java:977)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5431)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)"><pre class="notranslate"><span class="pl-en">Fatal</span> <span class="pl-pds">Exception</span>: <span class="pl-en">java</span><span class="pl-kos">.</span><span class="pl-en">lang</span><span class="pl-kos">.</span><span class="pl-v">IllegalArgumentException</span>: <span class="pl-v">You</span> <span class="pl-en">cannot</span> <span class="pl-en">start</span> <span class="pl-en">a</span> <span class="pl-en">load</span> <span class="pl-k">for</span> <span class="pl-en">a</span> <span class="pl-en">destroyed</span> <span class="pl-en">activity</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">bumptech</span><span class="pl-kos">.</span><span class="pl-en">glide</span><span class="pl-kos">.</span><span class="pl-en">manager</span><span class="pl-kos">.</span><span class="pl-en">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">assertNotDestroyed</span><span class="pl-kos">(</span><span class="pl-v">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:134</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">bumptech</span><span class="pl-kos">.</span><span class="pl-en">glide</span><span class="pl-kos">.</span><span class="pl-en">manager</span><span class="pl-kos">.</span><span class="pl-en">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-v">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:102</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">bumptech</span><span class="pl-kos">.</span><span class="pl-en">glide</span><span class="pl-kos">.</span><span class="pl-en">manager</span><span class="pl-kos">.</span><span class="pl-en">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-v">RequestManagerRetriever</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:87</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">bumptech</span><span class="pl-kos">.</span><span class="pl-en">glide</span><span class="pl-kos">.</span><span class="pl-en">Glide</span><span class="pl-kos">.</span><span class="pl-en">with</span><span class="pl-kos">(</span><span class="pl-v">Glide</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:620</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">myapp</span><span class="pl-kos">.</span><span class="pl-en">myapp</span>$24<span class="pl-kos">.</span><span class="pl-en">run</span><span class="pl-kos">(</span><span class="pl-v">MyAppClass</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:977</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">os</span><span class="pl-kos">.</span><span class="pl-en">Handler</span><span class="pl-kos">.</span><span class="pl-en">handleCallback</span><span class="pl-kos">(</span><span class="pl-v">Handler</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:739</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">os</span><span class="pl-kos">.</span><span class="pl-en">Handler</span><span class="pl-kos">.</span><span class="pl-en">dispatchMessage</span><span class="pl-kos">(</span><span class="pl-v">Handler</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:95</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">os</span><span class="pl-kos">.</span><span class="pl-en">Looper</span><span class="pl-kos">.</span><span class="pl-en">loop</span><span class="pl-kos">(</span><span class="pl-v">Looper</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:135</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">app</span><span class="pl-kos">.</span><span class="pl-en">ActivityThread</span><span class="pl-kos">.</span><span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-v">ActivityThread</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:5431</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">java</span><span class="pl-kos">.</span><span class="pl-en">lang</span><span class="pl-kos">.</span><span class="pl-en">reflect</span><span class="pl-kos">.</span><span class="pl-en">Method</span><span class="pl-kos">.</span><span class="pl-en">invoke</span><span class="pl-kos">(</span><span class="pl-v">Method</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">java</span><span class="pl-kos">.</span><span class="pl-en">lang</span><span class="pl-kos">.</span><span class="pl-en">reflect</span><span class="pl-kos">.</span><span class="pl-en">Method</span><span class="pl-kos">.</span><span class="pl-en">invoke</span><span class="pl-kos">(</span><span class="pl-v">Method</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:372</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">internal</span><span class="pl-kos">.</span><span class="pl-en">os</span><span class="pl-kos">.</span><span class="pl-en">ZygoteInit</span>$MethodAndArgsCaller<span class="pl-kos">.</span><span class="pl-en">run</span><span class="pl-kos">(</span><span class="pl-v">ZygoteInit</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:914</span><span class="pl-kos">)</span>
       <span class="pl-en">at</span> <span class="pl-en">com</span><span class="pl-kos">.</span><span class="pl-en">android</span><span class="pl-kos">.</span><span class="pl-en">internal</span><span class="pl-kos">.</span><span class="pl-en">os</span><span class="pl-kos">.</span><span class="pl-en">ZygoteInit</span><span class="pl-kos">.</span><span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-v">ZygoteInit</span><span class="pl-kos">.</span><span class="pl-en">java</span><span class="pl-pds">:707</span><span class="pl-kos">)</span></pre></div>