我想从通知操作按钮导航到撰写中的单个活动应用程序中的特定屏幕。根据此文档,我决定使用深层链接导航。问题是,当我单击通知操作按钮时,它会在导航到预期屏幕之前重新启动我的活动。如果我的活动在后台打开,我不希望它重新启动。
我就是这样做的:
这是我在应用程序清单中指定的内容:
<activity
android:name=".ui.AppActivity"
android:launchMode="standard"
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="myApp" android:host="screenRoute" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这是我的根导航图中的深层链接声明:
composable(
route = "screenRoute",
deepLinks = listOf(navDeepLink { uriPattern = "myApp://screenRoute" })
) {
ComposableScreen()
}
Run Code Online (Sandbox Code Playgroud)
这是我用于通知操作按钮的待处理意图:
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = "myApp://screenRoute".toUri()
}
val deepLinkPendingIntent = TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(intent)
getPendingIntent(1234, FLAG_UPDATE_CURRENT)
}
Run Code Online (Sandbox Code Playgroud)
我以为我在这里做错了什么,因为我没有找到任何关于这次重启的信息。因此,我下载了使用深层链接的官方撰写导航代码实验室(因为它也是单个应用程序活动),并且在使用来自意图的深层链接时执行相同的操作,活动将重新启动。
所以我的问题是: