I have the following project in Github where I used the Navigation component in it: https://github.com/alirezaeiii/Compose-Sample
In the Detail screen, I have a deepLink button that creates a pending intent and a notification :
val pendingIntent = findNavController()
.createDeepLink()
.setDestination(R.id.detailFragment)
.setArguments(args.toBundle())
.createPendingIntent()
Notifier.postNotification(args.poster, requireContext(), pendingIntent)
Here is how I generate the notification :
fun postNotification(poster: Poster, context: Context, intent: PendingIntent) {
val summary = NotificationCompat.Builder(context, channelId)
.setContentTitle(poster.name)
.setContentText(poster.release)
.setAutoCancel(true)
.setContentIntent(intent)
.setSmallIcon(R.drawable.donut_with_sprinkles)
.setGroup(poster.id.toString())
.setGroupSummary(true)
.build()
val notification = NotificationCompat.Builder(context, channelId)
.setContentTitle(poster.name)
.setContentText(poster.release)
.setAutoCancel(true)
.setContentIntent(intent)
.setSmallIcon(R.drawable.donut_with_sprinkles)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setGroup(poster.id.toString())
.build()
val notificationManager = NotificationManagerCompat.from(context)
notificationManager.apply {
notify(
"summary ${poster.id}",
0,
summary
)
notify(
"notification ${UUID.randomUUID()}",
0,
notification
)
}
}
When I generate multiple notifications, and then kill the app and resume the detail screen from notification items and exit the app, I start the app from the launcher icon, it seems two instances of the app exist since I need to click multiple times on the back button to exit the app. How can I resolve it?
Addenda
One working solution that I found for it was to add singleTop as launch mode to Activity instead of default one which is standard :
android:launchMode="singleTop"