The app1 module in this project demonstrates that the default implementation of
the getItemId(position:)
and containsItem(itemId:)
methods in
the FragmentStateAdapter
class result in the FragmentStateAdapter.notifyDataSetChanged()
call being a no-op. Specifically,
the Fragment
s in
the FragmentStateAdapter
remaining unchanged when the FragmentStateAdapter.notifyDataSetChanged()
method is called.
The app2 module in this project demonstrates the proper workaround for this issue. This Android
application demonstrates an alternative workaround wherein the Fragment
s in
the FragmentStateAdapter
are not recreated but instead receive a method invocation to update themselves.
See the ViewPagerAdapter
class for the place where the FragmentStateAdapter.notifyDataSetChanged()
call is picked up and passed on to
the Fragment
s. See
the MainActivity.onCreate(savedInstanceState:)
method for the place where
the ViewPagerAdapter is
associated to the ViewPager2.
See
the MainActivity.onOptionsItemSelected(item:)
method for the place where FragmentStateAdapter.notifyDataSetChanged()
is called.