ViewBinding

build.gradle (Module: app) android { buildFeatures { viewBinding true } } Activity.java setContentView((binding = ActivityMainBinding.inflate(getLayoutInflater())).getRoot()); Fragment.java return (binding = FragmentMainBinding.inflate(inflater, container, false)).getRoot();

Navigation

<androidx.fragment.app.FragmentContainerView android:name="androidx.navigation.fragment.NavHostFragment" android:id="@+id/nav_host_fragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" app:navGraph="@navigation/nav_graph" /> NavController (Fragment) navController = Navigation.findNavController(view); NavController (Activity) navController = ((NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment)).getNavController(); NavController (DialogFragment) navController = Navigation.findNavController(requireParentView());