0

I am having some error in my activity adapter using glide and also when I use on fragment. I am trying to load a video thumbnail when users send videos to each other.

Here is my code:

RequestOptions requestOptions = new RequestOptions();
requestOptions.isMemoryCacheable();
Glide.with(activity)
        .setDefaultRequestOptions(requestOptions)
        .load(dialogList.get(position).getVideoUrl()) // or URI/path
        .into(viewHolder.Right_videoview);

logcat:

Fatal Exception: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
   at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:323)
   at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:132)
   at com.bumptech.glide.Glide.with(Glide.java:732)
   at chat.espana.esp.adapter.ChatListAdapter.getView(ChatListAdapter.java:391)
   at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:232)
   at android.widget.AbsListView.obtainView(AbsListView.java:2511)
   at android.widget.ListView.makeAndAddView(ListView.java:2052)
   at android.widget.ListView.fillUp(ListView.java:820)
   at android.widget.ListView.layoutChildren(ListView.java:1793)
   at android.widget.AbsListView.onLayout(AbsListView.java:2304)
   at android.view.View.layout(View.java:19682)
   at android.view.ViewGroup.layout(ViewGroup.java:6086)
   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)

I appreciate some help. Thank you.

1 Answers1

0

Use:

Glide.with(getApplicationContext()).load(...)

Instead of:

Glide.with(TabMorePagesDetailActivity.this).load(...)

This will stop it from crashing, but will still use the resources to load the image even if the activity has been destroyed. –

https://stackoverflow.com/a/32887693/5595926

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50