Passing argument(s) to a nested Navigation architecture component graph

Global actions might be a way but I didn’t get that working as I wanted once I extracted the nested graph to its own .xml. But it turned out to be embarrassing simple – just add the arguments manually in code, to your action. An example related to the question would be: Save the nested … Read more

Android Navigation Component : Pass value (arguments) in fragments

Simple and fast solution: pass arguments between destinations Bundle bundle = new Bundle(); bundle.putString(“amount”, amount); Navigation.findNavController(view).navigate(R.id.confirmationAction, bundle); and receiving TextView tv = view.findViewById(R.id.textViewAmount); tv.setText(getArguments().getString(“amount”));

How to change start destination of a navigation graph programmatically?

UPDATE: When you have nav graph like this: <fragment android:id=”@+id/firstFragment” android:name=”com.appname.package.FirstFragment” > <action android:id=”@+id/action_firstFragment_to_secondFragment” app:destination=”@id/secondFragment” /> </fragment> <fragment android:id=”@+id/secondFragment” android:name=”com.appname.package.SecondFragment”/> And you want to navigate to the second fragment and make it root of your graph, specify the next NavOptions: NavOptions navOptions = new NavOptions.Builder() .setPopUpTo(R.id.firstFragment, true) .build(); And use them for the navigation: Navigation.findNavController(view).navigate(R.id.action_firstFragment_to_secondFragment, … Read more

Could Navigation Arch Component create a false positive memory leak?

That’s how Fragments on the back stack work (and Navigation just uses the existing Fragment APIs): the Fragment’s view is destroyed, but the Fragment itself is not destroyed – they are kept in the CREATED state until you hit the back button and return to the Fragment (after which onCreateView() will be called again and … Read more

Pass data back to previous fragment using Android Navigation

Android just released a solution for this; Passing data between Destinations (Navigation 2.3.0-alpha02), basically, in fragment A you observe changes in a variable and in fragment B you change that value before executing popBackStack(). Fragment A: findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<String>(“key”)?.observe(viewLifecycleOwner) { result -> // Do something with the result. } Fragment B: navController.previousBackStackEntry?.savedStateHandle?.set(“key”, result) navController.popBackStack()

How to create BottomSheetDialogFragment using Navigation Architecture Component?

In the navigation component version 2.1.0-alpha04, Navigation Graph can contain dialog as one of the destinations. <?xml version=”1.0″ encoding=”utf-8″?> <navigation xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:id=”@+id/main_navigation” app:startDestination=”@id/startFragment”> <fragment android:id=”@+id/loginFragment” android:name=”com.awesomeproject.android.authentication.login.LoginFragment” android:label=”Login” tools:layout=”@layout/login_fragment” /> <dialog android:id=”@+id/bottomSheet” android:name=”com.awesomproject.android.BottomSheetFragment” tools:layout=”@layout/bottom_sheet_dialog_fragment” /> </navigation> The BottomSheetFragment will look similar to other BottomSheet. class BottomSheetFragment : BottomSheetDialogFragment() { override fun onCreateView(inflater: LayoutInflater, container: … Read more

Proguard causing runtime exception with Android Navigation Component

I know that Proguard and R8 should be keeping all the children of library classes but in this case, the fragment class seems to be missing. This keep rule solved my issue but technically we should not need this rule at all! -keep class * extends android.support.v4.app.Fragment{} If you are using AndroidX, then use this … Read more

Android navigation component: how save fragment state

As per the open issue, Navigation does not directly support multiple back stacks – i.e., saving the state of stack B when you go back to B from A or C since Fragments do not support multiple back stacks. As per this comment: The NavigationAdvancedSample is now available at https://github.com/googlesamples/android-architecture-components/tree/master/NavigationAdvancedSample This sample uses multiple NavHostFragments, … Read more

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