我正在使用Glide在Android应用程序中从互联网加载图像。当用户单击注销按钮时,我通过清除所有共享的首选项并使用以下代码重新启动应用程序来注销用户:
Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage( getActivity().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
getActivity().finish();
,注销操作正常。但是,当用户再次登录时,我的应用程序崩溃了。
以下是日志详细信息:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.highavenue.android, PID: 21503
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:629)
at com.highavenue.android.adapter.ActivityTimelineAdapter.onBindViewHolder(ActivityTimelineAdapter.java:181)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
代码:(我在哪里以及如何使用Glide)
Glide.with(context)
.load(users_list.get(user_position).getProfileImageURL())
.thumbnail(0.1f)
.override(100, 100)
.into(holder.profile_image);
以上代码在RecyclerViewAdapter类中使用,其中context表示片段的上下文。
注意:当用户手动关闭应用并再次打开时,不会发生此异常。
答案 0 :(得分:0)
我相信这已经足够了(添加Intent.FLAG_ACTIVITY_CLEAR_TASK
):
Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage( getActivity().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
但是,根据同一问题in here的建议,您可以尝试使用:
Glide.with(YourActivityName.this) // or `getApplicationContext()`
而不是得到context
。这可能会解决错误。
答案 1 :(得分:0)
尝试一下
Glide.with(getApplicationContext()).load(...)
答案 2 :(得分:0)
该错误告诉您问题所在:
(def children (map :content))
(defn tagp [pred]
(filter (comp pred :tag)))
(defn tag= [tag-name]
(tagp (partial = tag-name)))
(def text (comp (mapcat :content) (filter string?)))
(defn fields [obj-datas]
(sequence (comp
(tag= :ObjectData)
(mapcat :content)
text)
obj-datas))
(defn clean [xml-map]
(let [fields-list (sequence (comp
(tag= :SoapObject)
children
(map fields))
xml-map)]
(map (partial apply hash-map) fields-list)))
因此,您在Activity上调用java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
后,您的Glide加载调用就会执行。
完成活动后,您需要防止调用Glide load方法。
鉴于您当前的代码,您可以设置一个标志或一些东西来告诉适配器不加载图像:
finish()
这不是最好的解决方案,但是鉴于我对您的代码了解很少,我可以想到的最好。
希望有帮助!