diff --git a/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/NotificationHelper.kt b/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/NotificationHelper.kt index af24e304..08c575c6 100644 --- a/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/NotificationHelper.kt +++ b/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/NotificationHelper.kt @@ -127,9 +127,10 @@ object NotificationHelper { intent.putExtra(NOTIFICATION_ID, data[NOTIFICATION_ID]) intent.putExtra(CURRENT_IMAGE_INDEX, currentIndex) + val requestCode = RequestCodeGenerator.generateRequestCode(action, currentIndex) return PendingIntent.getService( /* context = */ context, - /* requestCode = */ RequestCodeGenerator.getNextRequestCode(), + /* requestCode = */ requestCode, /* intent = */ intent, /* flags = */ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) diff --git a/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/RequestCodeGenerator.kt b/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/RequestCodeGenerator.kt index 45b09d4a..62f1015d 100644 --- a/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/RequestCodeGenerator.kt +++ b/personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/RequestCodeGenerator.kt @@ -1,11 +1,14 @@ package com.personalizatio.notification -import java.util.concurrent.atomic.AtomicInteger +import kotlin.math.abs object RequestCodeGenerator { - private val counter = AtomicInteger(0) - fun getNextRequestCode(): Int { - return counter.getAndIncrement() + /** + * Create a unique requestCode based on the hashcode of the combination of action and currentIndex + * */ + fun generateRequestCode(action: String, currentIndex: Int): Int { + val uniqueKey = "${action}_${currentIndex}".hashCode() + return if (uniqueKey != Int.MIN_VALUE) abs(uniqueKey) else 0 } -} \ No newline at end of file +}