Issue
I want to change my start navigation fragment based on a condition. My start fragment could be fragment one or two. Is there a way to implement it?
Solution
Check out this question and its solution // Also added Java code here
Just converted Kotlin code to Java
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.home_nav_fragment); // Hostfragment
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
NavGraph graph = inflater.inflate(R.navigation.nav_main);
graph.setDefaultArguments(getIntent().getExtras());
graph.setStartDestination(R.id.fragment1);
navHostFragment.getNavController().setGraph(graph);
navHostFragment.getNavController().getGraph().setDefaultArguments(getIntent().getExtras());
NavigationView navigationView = findViewById(R.id.navigationView);
NavigationUI.setupWithNavController(navigationView, navHostFragment.getNavController());
Answered By - Akash Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.