Abhishek AN
Abhishek AN

Reputation: 808

Navigation Component implicit deep link back press exits the app

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?

Upvotes: 1

Views: 1918

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

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.

Upvotes: 2

Related Questions