I'm using Glide to load the image from the internet in my android app. When the user click on the log out button, I'm logging out the user by clearing all the shared preferences and restarting the app by using the following code:
Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage( getActivity().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
getActivity().finish();
and the logout is perfectly working. But, when the user login again, My app get crashed.
Here is the log details:
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)
Code : (where and how I used Glide)
Glide.with(context)
.load(users_list.get(user_position).getProfileImageURL())
.thumbnail(0.1f)
.override(100, 100)
.into(holder.profile_image);
the above code was used in a RecyclerViewAdapter class, where context refers to the context of a fragment.
Note: This exception not occurs when the user manually closes the app and open again.