Android Jetpack: Introducing Navigation component
Why Stack Overflow recommends it
Stack Overflow users link it as the quick official overview of the Navigation component when answering questions about single-activity design, fragment navigation and bottom navigation.
Recommended by 3 people across 3 different months, 2019 to 2021.
What it is
A five-minute introduction from the Android Developers channel to the Jetpack Navigation component, covering the navigation graph, the Navigation Editor in Android Studio 3.3, Safe Args, deep linking and Navigation UI for drawers and bottom navigation. It is the official overview that points to docs and codelabs for more depth.
What people said
Recommends yonga springfield · 2019-01 · Stack Overflow · on “How to interact with other fragment when using Navigation architecture component?”
Will like to know so as to clarify myself. Why don't you want fragment A be destroyed when you navigation to fragment B? Guess if you won't want to loose fragment A's state, you can initialize it in a viewModel [LINK] and retrieve it in the onCreate of your activity( whichever lifecycle method of your fragment you determines sounds fit). If this wasn't the reason, plz do explain to provide us with a better context. For the navigation library way of swapping fragments out of the container. here's a brief summary of the navigation library [this video] As per the docs [LINK] (which I recommend you should read because it's a lengthy procedure with a lot fuzzy words. Assuming you are using at least An
Recommends MD Naseem Ashraf · 2019-03 · Stack Overflow · on “Android AppBarLayout with tabs and ViewPager”
Also, look into the newer tools that Google has introduced, like Navigation Component introduced in the Jetpack set of architecture tools. See this: [this video]
Recommends MD Naseem Ashraf · 2019-03 · Stack Overflow · on “Android Activity history tracking and clearing partially”
Also, look at newer available methods and tools for app navigation. You can start including these into your project; [LINK] [LINK] [this video] [LINK]
Recommends Caner Kaşeler · 2021-05 · Stack Overflow · on “Using the Navigation component with multiple activities”
Short Answer is Unnecessary because: In Navigation Component idea, you need to have 1 + 3 parts and unlimited fragments. You can watch Google Navigation Component Video [this video] . Only one Activity. Single Activity These are working in the one Activity ( Single Activity ). Navigation graph NavHostFragment NavController Why Unnecessary? Because, all parts of "1 + 3" connected with each other. Details : Navigation graph is connected with NavFostFragment. Moreover, NavFostFragment defines in XML file of Single Activity. Also, NavController defines by NavController as " navHostFragment.navController ". However , if you really really want to use Navigation Compenent for Activities, you need to use
Cites snersesyan · 2019-09 · Stack Overflow · on “Use same fragment multiple times in navigation graph”
I want to migrate my project to use navigation components. In my Activity there is a bottom navigation, which navigates through different instances of the same Fragment (with different arguments). Here [this video] explained about bottomNavigation support. But is it possible to reuse same Fragment in the same navigation graph, with different IDs and params? I can't find way in google documentations.
Cites Simon Harvan · 2021-04 · Stack Overflow · on “Android: Navigation Component with Tab Layout”
For viewpager solution you can refer to: viewpager ( [LINK] ) viewpager2 ( [LINK] ) Suppose you don't want to use a view pager with tablayout (which was my case). It seems that there is no built-in functionality for this ( [this video] ) [LINK] However, you can do a workaround like this for every time tab is selected: // In tab selected listener when(position) { 0 -> { navController.popBackStack() navController.navigate(R.id.CashRegister) } 1 -> { navController.popBackStack() navController.navigate(R.id.OECSettings) } }