0

I've an implicit deep link created just like mentioned in the docs.

https://developer.android.com/guide/navigation/navigation-deep-link#implicit

implicit - domain.com/ When I click on it, yhis opens a new instance of the activity, mentioned in the docs

If I press back it exits the app.

The documentation says it should go back to the previous app and reloads that fragment, what am I doing wrong here?

If the flag is not set, you remain on the task stack of the previous app where the implicit deep link was triggered. In this case, the Back button takes you back to the previous app, while the Up button starts your app's task on the hierarchical parent destination within your navigation graph.

What's the difference between back button and up button?

Abhishek AN
  • 648
  • 7
  • 24
  • How are you launching your deep link? Did your activity get launched with the `Intent.FLAG_ACTIVITY_NEW_TASK`? Are you testing with the system back button or the Up button? – ianhanniballake Oct 07 '21 at 15:57
  • @ianhanniballake It directly launches after tapping on the URL, the activity doesn't have the flag. The up button takes me to my app top, system back closes the app, I've overridden using the onbackpress callback to navigateUp() shouldn't this be doing the up action? – Abhishek AN Oct 07 '21 at 19:18
  • And by 'closes the app', you mean it returns you to the app where you tapped the URL? – ianhanniballake Oct 07 '21 at 23:01
  • Yes it does take me back, example tapped it on discord, goes there – Abhishek AN Oct 08 '21 at 07:33

1 Answers1

1

The documentation says it should go back to the previous app and reloads that fragment, what am I doing wrong here?

The docs you've specifically quote says that the system back will take you back to the app that deep linked into your app, so the behavior you are seeing is expected.

For example, if you click a link in the Discord app and that app doesn't use FLAG_ACTIVITY_NEW_TASK, then your app exists on Discord's task stack and are part of its back stack. This means that the system back button is expected to take you back to Discord.

As per the Principles of Navigation, the Up button functions differently when your activity is placed on another app's task stack:

The Up button never exists your app

When your app is launched using a deep link on another app's task, Up transitions users back to your app’s task and through a simulated back stack and not to the app that triggered the deep link. The Back button, however, does take you back to the other app.

So it is expected that the Up button always keeps the user in your app and the Up button will never return the user to the Discord app.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443