Skip to content

Issue with notify on Android (CLEAR_TOP) #148

@blackwiz4rd

Description

@blackwiz4rd

KMPNotifier and Kotlin version:
kmpnotifier version: 1.3.0, kotlin version: 2.0.21

Describe the bug.
The FLAG_ACTIVITY_CLEAR_TOP avoids multiple stacked instances of the launcher activity in android. However, this might not be the most appropriate way to start the activity for some users/use cases.
E.g. if the app is loaded in UI, it will reload the app (in my case it should not happen).
There should either be an option to skip this intent config or to allow passing flags (more robust for future uses).

Inside AndroidNotifier.kt, the intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) should be optional or configurable.

    private fun getPendingIntent(payloadData: Map<String, String>, id: Int): PendingIntent? {
        val intent = getLauncherActivityIntent()?.apply {
            putExtra(ACTION_NOTIFICATION_CLICK, ACTION_NOTIFICATION_CLICK)
            payloadData.forEach { putExtra(it.key, it.value) }
            val urlData = payloadData.getOrDefault(Notifier.KEY_URL, null)
            urlData?.let { setData(Uri.parse(urlData)) }
        }
        intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

        val flags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT


        return PendingIntent.getActivity(context, id, intent, flags)
    }

In which platform bug occurs?
android

To Reproduce
Steps to reproduce the bug:

  • launch any notification on android

Expected behavior
Avoid reloading the app activity when notification is clicked

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions