Get all the fragments from the stack in order

I use Snippets in my application project. All fragments are added to the back stack :

... fragmentTransaction.addToBackStack(null); ... 

Later, what is the correct way to get all the fragments from the back stack in order?

+4
source share
1 answer

Using getBackStackEntryCount() , you can iterate through the back stack and use the getBackStackEntryAt() method to get each fragment.

EDIT: Based on some of the discussions in the comments, it is recommended that you manually save the list of fragments that you added to your back and save them in your SharedPreferences. You can then read this list at application startup and reload these fragments.

+4
source

Source: https://habr.com/ru/post/1402246/


All Articles