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

Dynamic ActionBar title from a Fragment using AndroidX Navigation

As of 1.0.0-alpha08, you can have the NavigationUI bits dynamically set the title… if the dynamic bits are arguments on the navigation action. So, for example, in your navigation graph, you could have something like this: <fragment android:id=”@+id/displayFragment” android:name=”com.commonsware.jetpack.sampler.nav.DisplayFragment” android:label=”Title: {title}” > <argument android:name=”modelId” app:argType=”string” /> <argument android:name=”title” app:argType=”string” /> </fragment> Here, the android:label attribute … Read more

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

Is it possible to set startDestination conditionally using Android Navigation Architecture Component(Android Jetpack)?

Finally, I got a solution to my query… Put below code in onCreate() method of Activity. Kotlin code val navHostFragment = (supportFragmentManager.findFragmentById(R.id.home_nav_fragment) as NavHostFragment) val inflater = navHostFragment.navController.navInflater val graph = inflater.inflate(R.navigation.nav_main) //graph.addArgument(“argument”, NavArgument) graph.setStartDestination(R.id.fragment1) //or //graph.setStartDestination(R.id.fragment2) navHostFragment.navController.graph = graph Java code NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.home_nav_fragment); // Hostfragment NavInflater inflater = navHostFragment.getNavController().getNavInflater(); NavGraph graph … Read more

How to get a result from fragment using Navigation Architecture Component?

They have added a fix for this in the 2.3.0-alpha02 release. If navigating from Fragment A to Fragment B and A needs a result from B: findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Type>(“key”)?.observe(viewLifecycleOwner) {result -> // Do something with the result. } If on Fragment B and need to set the result: findNavController().previousBackStackEntry?.savedStateHandle?.set(“key”, result) I ended up creating two extensions for … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)