Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Version used: 2.8.3
Devices/Android versions reproduced on: Samsung S20, Samsung S21
Issue. If app is in background and deeplink is launched from other application:
- on "my_app://" deeplink, existing instance of the app is launched(which is what I expect)
- on "my_app://open_first_screen" deeplink, new activity is created, first screen opened, then previous Activity destroyed.
I need retain same MainActivity instance in both cases.
Project setup:
I have single Activity project with bottom bar navigation. Activity launchMode="singleTask", everything is setup by instructions using official docs. Manifest file looks like this:
<application>
...
<activity
android:name=".mainActivity.MainActivity"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my_app" />
</intent-filter>
</activity>
...
<application />
MainActivity navigation part looks like this:
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
setContent {
...
val navController = rememberNavController()
DisposableEffect(Unit) {
val listener = Consumer<Intent> {
navController.handleDeepLink(it)
}
this@MainActivity.addOnNewIntentListener(listener)
onDispose { this@MainActivity.removeOnNewIntentListener(listener) }
}
LaunchedEffect(Unit) {
navController.addOnDestinationChangedListener{...}
}
MainScreen(...)
}
}
...
}
MainScreen navigation part:
@Composable
MainScreen(
navController: NavHostController,
...
) {
Scaffold(...) {
NavHost(navController = navController, ...) {
firstGraph()
secondGraph()
}
}
}
private fun NavGraphBuilder.firstGraph() {
navigation<Graph.FIrstGraph>(startDestination = Route.FirstScreen) {
firstScreen()
secondScreen()
}
}
private fun NavGraphBuilder.secondGraph() {
navigation<Graph.SecondGraph>(startDestination = Route.ThirdScreen) {
thirdScreen()
fourthScreen()
}
}
The screen which accepts deeplink looks like this:
private fun NavGraphBuilder.firstScreen(navController: NavController, ...) {
composable<Route.FirstScreen>(
deepLinks = listOf(
navDeepLink { uriPattern = "my_app://open_first_screen" }
)
) {...}
}
Could anybody have a look? (issue described in the beginning)