I have this nav_graph.xml file:
<?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/nav_graph"
app:startDestination="@id/first_fragment">
<fragment
android:id="@+id/first_fragment"
android:name="FirstFragment"
android:label="First"
tools:layout="@layout/layout">
</fragment>
<fragment
android:id="@+id/second_fragment"
android:name="SecondFragment"
android:label="Second"
tools:layout="@layout/layout">
<argument
android:name="element"
app:argType="Element"
android:defaultValue="@null"
app:nullable="true" />
</fragment>
<fragment
android:id="@+id/third_fragment"
android:name="ThirdFragment"
android:label="Third"
tools:layout="@layout/layout">
<argument
android:name="element"
app:argType="Element"
android:defaultValue="@null"
app:nullable="true" />
</fragment>
</navigation>
And I want to pass the element
object from the first fragment to the last one. What I do, I add that element
as an argument in each fragment. Is there any way I can define it only once, and use it in all fragments? Something like a global variable (argument)?