The Navigation Architecture Component Tutorial: Getting Started | Ray Wenderlich

Hey there. I am really new to your site but have found it very impressive so far. At any rate, I was (am) trying to get this tutorial to work to aid me in adding DialogFragments to my app that already has a nav_graph.

I ran into two issues:

(1) AuthorDetailsNavigator.kt:

Class ā€˜AuthorDetailsNavigatorā€™ is not abstract and does not implement abstract base class member @Nullable public abstract fun navigate(@NonNull destination: AuthorDetailsNavigator.Destination, @Nullable args: Bundle?, @Nullable navOptions: NavOptions?, @Nullable navigatorExtras: Navigator.Extras?): NavDestination? defined in androidx.navigation.Navigator

If I [Alt-Enter] and [Implement members] and select [navigate], the error goes away. I changed your (original)

    override fun navigate(destination: Destination, args: Bundle?, navOptions: NavOptions?) {
    val dialog = AuthorDetailsDialog()
    dialog.arguments = args
    dialog.show(manager, AuthorDetailsDialog.TAG)
  }

to

    override fun navigate(destination: Destination, args: Bundle?, navOptions: NavOptions?, navigatorExtras: Extras?): NavDestination? {
        return NavDestination(this)        
    }

Does that seem correct? And, if so, are any of the other routines in this class no longer needed?

(2) MainActivity.kt:

Unresolved reference: onHandleDeepLink twice

I made the change mentioned above for (1) and commented out the two offending lines in (2) and the app compiles and runs fine.

Except that Iā€™m not seeing the AuthorDetails DialogFragment, which was (is) my whole purpose in undertaking this exercise.

Any thoughts?

Note: I have some ā€œproject differencesā€ from your original source. Notably:

  • gradle/wrapper/gradle-wrapper.properties ā†’ distā€¦Url=ā€¦gradle-4.10.1-all.zip (not ā€œ4.6ā€)
  • app/build.gradle ā†’ implā€¦arch.navigation:navigation-fragment-ktx:1.0.0" (no ā€œ-alpha05ā€)
  • app/build.gradle ā†’ implā€¦arch.navigation:navigation-ui-ktx:1.0.0" (no ā€œ-alpha05ā€)

Thanks.

Hi,

the issues in the code are happening because of newer versions of navigation-fragment-ktx and navigation-ui-ktx libraries.

(1) In order to get the dialog to show you should make the following changes to the new override of navigate method:

    override fun navigate(destination: Destination, args: Bundle?, navOptions: NavOptions?, navigatorExtras: Extras?): NavDestination? {
      val dialog = AuthorDetailsDialog()
      dialog.arguments = args
      dialog.show(manager, AuthorDetailsDialog.TAG)

      return createDestination()
    }

The method was changed in 1.0.0 version of the library to return NavDestination that will be added to the backstack. You can check the official method doc for more info.

(2) Errors in MainActivity.kt are happening because onHandleDeepLink(Intent) method was renamed to handleDeepLink(Intent). Also, it should now be automatically called when graph is created. This means that you only have to call it from onNewIntent() now in order for deep links to work properly:

override fun onNewIntent(intent: Intent?) {
  super.onNewIntent(intent)
  findNavController(this, R.id.navHostFragment).handleDeepLink(intent)
}

Best,
Ivan

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!