STAR-ZERO / navigation-keep-fragment-sample

392 stars 63 forks source link

help me #4

Closed diorslau closed 5 years ago

diorslau commented 5 years ago

Hello, I wrote it according to your code, and then it ran wrong. I hope I can help me.

Caused by: java.lang.IllegalStateException: Could not find Navigator with name "keep_state_fragment". You must call NavController.addNavigator() for each navigation type.

diorslau commented 5 years ago

code:

    NavHostFragment navHostFragment = (NavHostFragment) mFragmentManager.findFragmentById(R.id.fragment);
    KeepStateNavigator navigator = new KeepStateNavigator(this, navHostFragment.getChildFragmentManager(), R.id.fragment);

    NavController navController = navHostFragment.getNavController();
    navController.getNavigatorProvider().addNavigator(navigator);

    NavigationUI.setupWithNavController(mBinding.navigation, navController);
STAR-ZERO commented 5 years ago

Probably, you need to call navController.setGraph.

STAR-ZERO commented 5 years ago

Let me close. If you have any problem, please tell me.

gerardoepitacio commented 5 years ago

@diorslau did you solve this?

Update Try removing app:navGraph="@navigation/nav_graph" in nav_host_fragment item.

tianxm commented 4 years ago

@diorslau did you solve this?

Update Try removing app:navGraph="@navigation/nav_graph" in nav_host_fragment item.

great, this work

DenisMakovskyi commented 4 years ago

Try to extend NavHostFragment by your custom fragment StatefulNavHostFragment: NavHostFragment() and override onCreateNavController, where you can add your naviagator.

This problem is probably occurs because nav inflater is trying to inflate your graph, and at this moment he know nothing about your navigator.

iamsr commented 4 years ago

If anyone still facing the problem please remove the app:navGraph="" from your host fragment and while seting up this navigator first set navigator then set graph.

netcyrax commented 4 years ago

Hey! Thanks for the pointers, but when I remove app:navGraph then val navHostFragment = parentFragmentManager.findFragmentById(R.id.navHostView)!! throws null pointer exception. Does anyone encountered this?