Passing data in android navigation architecture component part-2

Rajesh Khadka
Incwell Technology
Published in
3 min readAug 1, 2018

--

  1. Type Unsafe Way

Lets pass data between two fragments:

send username from main -> dashboard

First add the navigation from the main fragment to dashboard fragment using android studio’s editor for navigation as outline in gif.

procedure to add navigation and arugment

After adding navigation you will see the <action/> has been added in app_nav.xml. we can have same action id in multiple fragments destination because it is inside the context of fragments.

<action
android:id="@+id/action_nav_main_to_nav_dashboard"
app:destination="@id/nav_dashboard" />
// will reference the id while navigating form main fragment

Define the argument username in that navigation in app_nav.xml

<argument
android:name="username"
app:type="string" />

After adding the destinations and argument app_nav.xml will be:

--

--