{"id":1258,"date":"2023-03-18T09:48:46","date_gmt":"2023-03-18T01:48:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1258"},"modified":"2023-04-29T09:28:03","modified_gmt":"2023-04-29T01:28:03","slug":"glide-error-illegalargumentexception-you-cannot-start-a-load-for-a-destroyed-activity","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/glide-error-illegalargumentexception-you-cannot-start-a-load-for-a-destroyed-activity\/","title":{"rendered":"Glide\u9519\u8befIllegalArgumentException You cannot start a load for a destroyed activity"},"content":{"rendered":"<h2>\u95ee\u9898\u63cf\u8ff0<\/h2>\n<p>Glide\u5728Activity\u6216Fragment\u9500\u6bc1destroy\u65f6\u62a5\u9519\uff1a<\/p>\n<pre><code>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>\u89e3\u51b3\u529e\u6cd5<\/h2>\n<p>\u4f7f\u7528Glide\u52a0\u8f7d\u56fe\u7247\u65f6\u5224\u65adcontext\u662f\u5426\u4e3a\u7a7a\u3001\u6216\u4f7f\u7528ApplicationContext\u3001\u6216\u5224\u65ad\u5f53\u524dActivity\u662f\u5426\u88ab\u9500\u6bc1<\/p>\n<pre><code class=\"language-java\">if (context !=null) {\n    mGlideRequest = Glide.with(context).load(url).placeholder(R.drawable.default_img).dontAnimate().error(R.drawable.error_img);\n}<\/code><\/pre>\n<pre><code class=\"language-java\">Glide.with(getActivity().getApplicationContext())<\/code><\/pre>\n<p>\u539fissue\u5730\u5740\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/bumptech\/glide\/issues\/803\">https:\/\/github.com\/bumptech\/glide\/issues\/803<\/a><br \/>\n\u53c2\u8003\uff1a <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/31964737\/glide-image-loading-with-application-context\/32887693#32887693\">https:\/\/stackoverflow.com\/questions\/31964737\/glide-image-loading-with-application-context\/32887693#32887693<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/39093730\/you-cannot-start-a-load-for-a-destroyed-activity-in-relativelayout-image-using-glide\">https:\/\/stackoverflow.com\/questions\/39093730\/you-cannot-start-a-load-for-a-destroyed-activity-in-relativelayout-image-using-glide<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0 Glide\u5728Activity\u6216Fragment\u9500\u6bc1destroy\u65f6\u62a5\u9519\uff1a java.lang.Ill [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[206],"tags":[209],"class_list":["post-1258","post","type-post","status-publish","format-standard","hentry","category-android-image-loader","tag-glide"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1258"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1258\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}