0

I have a problem about activity created twice.

When the notification appears, the activity will appear because of the fullscreen intent. At this time, I press the home button and click the notification, and the activity is actually created again.

I tried to use singletop and it didn't work. Log shows the same task, but the hash is different.

Log.e("Task", "task id: $taskId, hash: ${hashCode()}")
        val pendingIntent = PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java).apply {
            addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
        }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)

        val builder = NotificationCompat.Builder(context, "Alarm")
            .setSmallIcon(R.drawable.ic_launcher_background)
            .setContentTitle("Title")
            .setContentText("Content")
            .setContentIntent(pendingIntent)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setFullScreenIntent(pendingIntent, true)
Joe199382
  • 199
  • 1
  • 12
  • Why are you using NEW_TASK and CLEAR_TASK? This will definitely create a new `Activity`. If the app is already running, do you just want to bring it to the foreground? Or do you want to start a new `Activity`? – David Wasser Nov 16 '21 at 11:57
  • @DavidWasser Even if I remove the flag, it still cannot achieve the effect of singleTask – Joe199382 Nov 17 '21 at 12:06
  • please explain what you want to happen. Your requirements are not clear. Also, have you set any launchMode in the manifest? – David Wasser Nov 17 '21 at 12:48
  • Also, please edit your question and post your manifest. – David Wasser Nov 17 '21 at 12:49

0 Answers0