Invalidation of Fragments managed by FragmentStateAdapter of ViewPager2

Viewed 280

My setup is as follows:

  • ViewPager2 instance uses ...
  • FragmentStateAdapter as the adapter.
  • getSupportFragmentManager was passed to constructor of FragmentStateAdapter.

The task

In some situations I would like the Fragments to be recreated "from scratch" rather then from their savedInstanceState. In other words, I would like to tell the ViewPager2/FragmentStateAdapter/FragmentManger not to pass savedInstanceState bundle down to Fragment.onCreate(Bundle).

Question

Is there some way to 'invalidate' cache or whatever of ViewPager2/FragmentStateAdapter/FragmentManager so I could control when the Fragment should be 'invalidated' (when the Fragment should be created "from scratch" rather then from its savedInstanceState)?

Possible solution (insufficient for my needs)

I know that there are FragmentStateAdapter.getItemId(int) and FragmentStateAdapter.containsItem(long) which can be used to control instantiation of Fragments. However, this solution requires a proper management of (in my case hundreds of) IDs and somehow update/modify them each time the Fragments should be recreated.

Isn't there really a way to invalidate some kind of global cache?

0 Answers
Related