I have a problem with the navigation component. The problem is when call requireActivity, requireVIew and requireContext return Fragment not attached to an activity when executed this in onViewCreated. However, the problem is interesting because it does not occur all the time but in specific cases.
I have fragments A, B and C.
Application start, in fragment A i have a button to functionality, but first checking if user is signed in, if not, move to fragment B, if the user does not want to sign in or register, move from fragment B to fragment C. User can change fragments by BottomNavigation, so can move again to fragment A and try to sign in again in fragment B. Now, when user press button sign in application crash with information "Fragment not attached to an activity". Its odd, because when first time open fragment B and click sign in, its work normally, nothing crash. To open fragment B using
Navigation.findNavController(requireActivity(),
R.id.nav_host_fragment).navigate(FragmantADirections.actionFragmentAToFragmentB(someData));
if user does not want to sign in and click back button using
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navigate(FragmantBDirections.actionFragmentBToFragmentC());
}};