Navigation Architecture Component- Passing argument data to the startDestination

OK, I found a solution to that problem thanks to Ian Lake from the Google team. Let say you have an activity A that will start activity B with some intent data and you want to get that data in the startDestination you have two options here if you using safe args which is my … Read more

Android Jetpack Navigation, BottomNavigationView with Youtube or Instagram like proper back navigation (fragment back stack)?

You don’t really need a ViewPager to work with BottomNavigation and the new Navigation architecture component. I have been working in a sample app that uses exactly the two, see here. The basic concept is this, you have the main activity that will host the BottomNavigationView and that is the Navigation host for your navigation … Read more

Fragments destroyed / recreated with Jetpack’s Android Navigation components

Ian Lake from google replied me that we can store the view in a variable and instead of inflating a new layout, just return the instance of pre-stored view on onCreateView() Source: https://twitter.com/ianhlake/status/1103522856535638016 Leakcanary may show this as leak but its false positive..

IllegalStateException: Link does not have a NavController set

Officially recommended solution Currently using the FragmentContainerView is not very friendly, you have to access it from the supportFragmentManager: val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment val navController = navHostFragment.navController In my xml my FragmentContainerView looks like this: <androidx.fragment.app.FragmentContainerView android:id=”@+id/nav_host_fragment” android:name=”androidx.navigation.fragment.NavHostFragment” android:layout_width=”0dp” android:layout_height=”0dp” app:defaultNavHost=”true” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”parent” app:navGraph=”@navigation/nav_graph” /> This has been tested with androidx … Read more

IllegalArgumentException: navigation destination xxx is unknown to this NavController

In my case, if the user clicks the same view twice very very quickly, this crash will occur. So you need to implement some sort of logic to prevent multiple quick clicks… Which is very annoying, but it appears to be necessary. You can read up more on preventing this here: Android Preventing Double Click … Read more

How to clear navigation Stack after navigating to another fragment in Android

First, add attributes app:popUpTo=’your_nav_graph_id’ and app:popUpToInclusive=”true” to the action tag. <fragment android:id=”@+id/signInFragment” android:name=”com.glee.incog2.android.fragment.SignInFragment” android:label=”fragment_sign_in” tools:layout=”@layout/fragment_sign_in” > <action android:id=”@+id/action_signInFragment_to_usersFragment” app:destination=”@id/usersFragment” app:launchSingleTop=”true” app:popUpTo=”@+id/main_nav_graph” app:popUpToInclusive=”true” /> </fragment> Second, navigate to the destination, using above action as parameter. findNavController(fragment).navigate( SignInFragmentDirections.actionSignInFragmentToUserNameFragment()) See the docs for more information. NOTE: If you navigate using method navigate(@IdRes int resId), you won’t get the … Read more