I'm using ViewPager2 and with FragmentStateAdapter to retain state of fragments. I show 2 fragments in the pager when user is loggedOut but when user logins again the i want to recreate only the 2nd fragment to show another fragment in its replacement without impacting on first fragment. But when I call notifyDataSetChanged then ViewPager doesn't recreate the fragment. If I override getItemId method then createFragment method is called but still old fragment is showing. What could be the possible issue?
@Override
public long getItemId(int position) {
if (redrawFragments && position == 1) {
redrawFragments = false;
return -1;
}