Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android popBackStackImmediate can not remove Glide's SupportRequestManagerFragment

activity.supportFragmentManager.popBackStackImmediate()

popBackStackImmediate can not remove Glide's SupportRequestManagerFragment, do you know why? and is there any other way I can remove the SupportRequestManagerFragment from fragments stack?

like image 847
Expert wanna be Avatar asked Sep 03 '18 04:09

Expert wanna be


2 Answers

This case fragment use Activity context instead of fragment context for Glide.

Glide.with(getActivity()).load("url").into(imageView)

more details refer Here

If SupportRequestManagerFragment is getting added to backstack entry of your application fragments stack, then inside fragment call Glide method using base context so its not added and create problem for back press..

Glide.with(this.getActivity().getBaseContext()).load("url").into(imageView)
like image 104
sasikumar Avatar answered Oct 20 '22 12:10

sasikumar


Because Glide's Fragment is not on the FragmentManager's operation backstack.

See code.

pendingSupportRequestManagerFragments.put(fm, current);
fm.beginTransaction().add(current, FRAGMENT_TAG).commitAllowingStateLoss(); // <-- no addToBackStack() call

You probably also shouldn't touch the internals of Glide without good reason, but technically you can call fragmentManager.getFragments(), check for null (it can return null), iterate the list, check if(fragment instanceof SupportRequestManagerFragment), and if yes, then remove it with a fragment transaction. But it doesn't seem like a good idea. ^_^

like image 35
EpicPandaForce Avatar answered Oct 20 '22 10:10

EpicPandaForce