Skip to content

Commit e5cfc90

Browse files
committed
Add deeplink-guide
Guide that covers basic principles of deep linking and demonstrates how to apply them in Navigation 3
1 parent eb5de52 commit e5cfc90

File tree

3 files changed

+418
-45
lines changed

3 files changed

+418
-45
lines changed

app/src/main/java/com/example/nav3recipes/deeplink/advanced/AdvancedCreateAdvancedDeepLinkActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal const val ADVANCED_PATH_BASE = "https://www.nav3deeplink.com"
3232
* the MainActivity that you deeplink into. That module shows you how to build a synthetic backStack
3333
* and how to manage the Task stack properly in order to support both Back and Up buttons.
3434
*
35-
* See the [README] file of current module for more info on advanced deep linking.
35+
* See the [README](README.md) file of current module for more info on advanced deep linking.
3636
*/
3737
class AdvancedCreateAdvancedDeepLinkActivity: ComponentActivity() {
3838

@@ -118,4 +118,4 @@ private val MENU_OPTIONS_LOCATION = mapOf(
118118

119119
private val MENU_OPTIONS_TASK_STACK = mapOf(
120120
TAG_TASK_STACK to listOf(TAG_CURRENT_TASK, TAG_NEW_TASK),
121-
)
121+
)
Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Deep Link Advanced Recipe
22

3-
This recipe demonstrates how to build a synthetic backStack and support Back vs Up button
4-
through managing the Task stack.
3+
This recipe demonstrates how to apply the principles of navigation in the context of deep links by
4+
managing a synthetic backStack and Task stacks.
55

6-
# How it works
6+
# Recipe Structure
77
This recipe simulates a real-world scenario where "App A" deeplinks
88
into "App B".
99

@@ -15,45 +15,12 @@ trigger that in either the existing Task, or in a new Task.
1515
the MainActivity that you deeplink into. That module shows you how to build a synthetic backStack
1616
and how to manage the Task stack properly in order to support both Back and Up buttons.
1717

18-
# Synthetic BackStack
19-
A backStack that simulates the user manually navigating from the root screen to the deeplink screen.
20-
In general it should be built when the deeplinked Activity is started in a new
21-
Task stack. See below sections for more details.
18+
# Core implementation
19+
A couple classes of note:
2220

23-
# Back Button
24-
The Back button should direct users back the previous screen. However, what this "previous screen"
25-
is depends on whether the deeplinked screen was opened in the original Task (with App A as
26-
root Activity), or in a new Task.
21+
1. **navigate up** is demonstrated in [Navigator](../../../../../../../../../appdeeplink/src/main/java/com/example/nav3recipes/deeplink/app/util/Navigator.kt)
22+
2. **synthetic backStack** is demonstrated in [buildBackStack](../../../../../../../../../appdeeplink/src/main/java/com/example/nav3recipes/deeplink/app/util/BackStackUtil.kt)
2723

28-
In the first case with the original Task, the Back button should bring the user back to the
29-
screen that triggered the deeplink. Note: Depending on the actual
30-
app, you can arguably also create a synthetic backstack here if you want a different back behavior.
31-
32-
In the second case with a new Task, the Back button should
33-
bring the user to the hierarchical PARENT of the current screen. A synthetic backStack here
34-
ensures that the user backs into the expected screen.
35-
36-
# Up Button
37-
The Up button should direct the users to the hierarchical PARENT of the current screen.
38-
Furthermore, the Up button should never bring the user out of deeplinked app.
39-
This means the root screen should NOT have the Up button.
40-
41-
A synthetic backStack here ensures that users are correctly directed to the PARENT screen.
42-
As mentioned, a synthetic backStack should be built / is built when starting a new Task.
43-
This means that if the deeplinked Activity were started in the original Task, the
44-
Activity should be restarted with Intent.FLAG_ACTIVITY_NEW_TASK. This flag would trigger the
45-
Activity to restart in a new Task, which in turn should trigger the building of a synthetic backStack.
46-
47-
## Task & backStack illustration
48-
49-
**Original Task**
50-
| Task | Target | Synthetic backStack |
51-
|-------------|--------------------------------|------------------------------------------------|
52-
| Up Button | Deeplinked Screen's Parent | Restart Activity on new Task & build backStack |
53-
| Back Button | Screen that triggered deeplink | None |
54-
55-
**New Task**
56-
| Task | Target | Synthetic backStack |
57-
|-------------|--------------------------------|------------------------------------------------|
58-
| Up Button | Deeplinked Screen's Parent | Build backStack on Activity creation |
59-
| Back Button | Deeplinked Screen's Parent | Build backStack on Activity creation |
24+
# Further Read
25+
Check out the [deep link guide](../../../../../../../../../docs/deeplink-guide.md) for a
26+
comprehensive guide on Deep linking principles and how to apply them in Navigation 3.

0 commit comments

Comments
 (0)