Is there a way to remove all fragments which already added the specific view with its view id?
For example I want to remove all fragments which is added R.id.fragmentcontainer view.
Is there a way to remove all fragments which already added the specific view with its view id?
For example I want to remove all fragments which is added R.id.fragmentcontainer view.
Use this code
Hope it helps.
Thank you.
In case someone is looking for a code in Kotlin:
Try this, hope it helps :D
You can try below code
*frag is the object of fragment that you want to remove.
it will remove the fragment that is loded in "your_container" container.
HapPy coding.
Save all your fragments in an ArrayList.
Initializing:
Adding fragment to list:
When you want to remove all them, do the following:
I have used this method in production for years, and it works like a charm. Let me know if you have any questions.
More optimized version
There is no need in multiple call of commit so lets call it one time at the end