1

I have a fragment A which contains this code :

<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent">

    .......

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/children_container"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/layout_navigation" />

    .......

</RelativeLayout>

that start my fragment B. I would like to know how I can pass some argument from fragmentA and get in my fragmentB.

By reading this link but its talked about Activity A from Activity B.

I tried to remove this line from my FragmentContainerView

app:navGraph="@navigation/layout_navigation"

And in my fragmentA I added this following line :

val bundle = Bundle().apply {
    putString(KEY, "value")
}

NavHostFragment.create(R.navigation.layout_navigation, bundle)

In my fragment B, my arguments is null

Do you have any idea?

LikseN
  • 169
  • 1
  • 1
  • 7
  • `NavHostFragment.create(R.navigation.layout_navigation, bundle)` I don't understand this line at all. You should be using `Navigation.findNavController(this).navigate(R.id.some_destination, bundle)`. – EpicPandaForce Apr 26 '20 at 03:32
  • 1
    for some reason I had to do this .. : `val fragment = childFragmentManager.findFragmentById(R.id.children_container) ?: return` `val navController = NavHostFragment.findNavController(fragment)` Then it works ... – LikseN Apr 27 '20 at 08:32

0 Answers0