每次打开应用程序时,都会保留PendingIntent用于通知

时间:2020-08-30 14:32:01

标签: android kotlin android-architecture-navigation

我正在使用Navigation组件api,有一个具有以下流程的应用程序:StandBy(片段)=> Aptos(片段)=> PersonImage(对话框)

当应用程序收到通知时,使用NavDeepLinkBuilder我为通知创建了一个带有目标PersonFragment的挂起意图,并且单击它时,触发得很好(成功打开PersonImage对话框,并且后堆栈正常工作),但问题是:甚至当我从“最近”(系统屏幕)返回到应用程序时,按几次后退按钮关闭应用程序后,它将再次直接进入“ PersonImage”对话框。我不确定为什么会这样,因为我希望启动时该应用仅打开StandBy片段(导航图的startDestination),所以我猜这是通知的未决意图,它会在每次打开时触发并触发应用程序之类的东西,但我似乎无法弄清楚。 当我从启动器图标打开应用程序时,尽管它按预期运行(该应用程序以StandBy片段而不是PersonImage对话框启动)

fun buildNotificationBig(
    context: Context,
    title: String,
    description: String,
    channel: String,
    photoBitmap: Bitmap? = null,
    photoUrl: String? = null,
): Notification = NotificationCompat.Builder(context, channel).apply {
    setSmallIcon(R.mipmap.ic_launcher)
    setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
    setContentTitle(title)
    setContentText(description)

    val channelData = CHANNELS[channel] ?: throw IllegalStateException("There is no channel for id = $channel")
    color = channelData.color
    setSound(channelData.sound)
    if (photoUrl != null && channelData.idDestination != null){
       val pendingIntent = NavDeepLinkBuilder(context)
           .setGraph(R.navigation.mobile_navigation)
           .setDestination(channelData.idDestination)
           .setArguments(
               PersonImgDialogArgs(photoUrl = photoUrl).toBundle()
           )
           .createPendingIntent()
       setContentIntent(pendingIntent)
   }
   priority = channelData.importance.asNotificationPriority()
   setAutoCancel(true)
}.build()

0 个答案:

没有答案
相关问题