The Navigation component is part of Android Jetpack and simplifies navigation within your app, enabling developers to manage app navigation in a consistent manner. It provides an easy way to handle fragment transactions, deep linking, and passing data between destinations.
To use the Navigation component in your Android app, follow these steps:
dependencies {
def nav_version = "2.3.5" // Check for the latest version
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}
NavHostFragment
that displays your fragment destinations:
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController);
You can navigate between destinations easily using the following methods:
navController.navigate(R.id.action_firstFragment_to_secondFragment);
To handle up navigation, override onSupportNavigateUp in your Activity:
@Override
public boolean onSupportNavigateUp() {
return NavigationUI.navigateUp(navController, null) || super.onSupportNavigateUp();
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?