androiddeep-linkingandroid-architecture-navigationnavigation-architecture

Deep link navigating to parent activity does not work with navigation architecture component explicit deep link


I have a profile activity and MainActivity which is the parent of Profile Activity. I have a common activity with no ui to handle deep links re-direction using explicit deep links

Manifest file

 <activity
        android:name=".ui.profile.ProfileActivity"
        android:screenOrientation="portrait"
        android:parentActivityName="com.peoplemesh.now.ui.MainActivity" >

    <!-- Parent activity meta-data to support 4.0 and lower -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".ui.MainActivity" />
</activity>

Deep link activity code

val pendingIntent = NavDeepLinkBuilder(this)
    .setGraph(R.navigation.profile_nav)
    .setDestination(R.id.profileFrag)
    .setArguments(bundle)
    .setComponentName(ProfileActivity::class.java)
    .createPendingIntent()

pendingIntent.send(0)

Profile screen

navController.setGraph(R.navigation.profile_nav, bundle)

val appBarConfiguration = AppBarConfiguration(
    topLevelDestinationIds = setOf(),
    fallbackOnNavigateUpListener = ::onSupportNavigateUp
)

mBinding.toolbar.setupWithNavController(navController, appBarConfiguration)

Deep link to ProfileActivity -> up navigate -> closes app ( since there is not activity in stack).

How do i fix this?.

Update:

Not sure if this is of any help or a similar issue reported https://issuetracker.google.com/issues/142379671?pli=1


Solution

  • Ok. I found an answer after putting debug break point and going through the framework code. Seems this is a bug.

    What i did was override the default behaviour. Source - NavUtils.navigateUpTo() does not start any Activity

        override fun onSupportNavigateUp(): Boolean {
    
            val upIntent = NavUtils.getParentActivityIntent(this)
            if (NavUtils.shouldUpRecreateTask(this, upIntent!!) || isTaskRoot) {
                TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(upIntent)
                    .startActivities()
            } else {
                NavUtils.navigateUpTo(this, upIntent!!)
            }
            return true
    }
    

    This indeed works

    I also had this

       val appBarConfiguration = AppBarConfiguration(
            topLevelDestinationIds = setOf(),
            fallbackOnNavigateUpListener = ::onSupportNavigateUp
        )
    
        toolbar
            .setupWithNavController(navController, appBarConfiguration)