You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
5
5
6
-
# How it works
6
+
# Recipe Structure
7
7
This recipe simulates a real-world scenario where "App A" deeplinks
8
8
into "App B".
9
9
@@ -15,45 +15,12 @@ trigger that in either the existing Task, or in a new Task.
15
15
the MainActivity that you deeplink into. That module shows you how to build a synthetic backStack
16
16
and how to manage the Task stack properly in order to support both Back and Up buttons.
17
17
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:
22
20
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)
27
23
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.
0 commit comments