aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 247 forks source link

The launchNotification is null after clicking on a notification if the Android OS has destroyed the activity. #5496

Open tomlocksapps opened 1 month ago

tomlocksapps commented 1 month ago

Description

Hi, I'm trying to implement the Push Notifications API in my app, and I've noticed that it doesn't work properly when the activity is destroyed by the system. This issue can be easily reproduced by enabling the 'Don't keep activities' option in the system settings.

I tested it on both an API 34 emulator and a Samsung S21.

Categories

Steps to Reproduce

  1. Go to System Settings -> System -> Developer options -> enable "Don't keep activities".
  2. Open the app.
  3. Press home button.
  4. Open push message.
  5. Amplify.Notifications.Push.launchNotification is null.

Screenshots

No response

Platforms

Flutter Version

3.24.3

Amplify Flutter Version

2.4.1

Deployment Method

Amplify Gen 2

Schema

No response

Equartey commented 1 month ago

Hi @tomlocksapps, Thank you for submitting this. We will investigate and provide an update when we can.

NikaHsn commented 1 month ago

@tomlocksapps would you please provide answers to the following questions, thanks.

tomlocksapps commented 1 month ago

when you click on the push message does it trigger the onNotificationOpened?

No, it’s not called.

do you see the same behaviour without enabling the 'Don't keep activities' option in the system settings and instead reciving a push notification when the app is terminated?

No. When 'Don't keep activities' is OFF then everything works as expected. onNotificationOpened is called.

which google services plugin version do you use and can you please provide the plugin id you use in your gradle file?

id "com.google.gms.google-services" version "4.3.15" apply false

I extracted the logs from the app, so you can see the difference when 'Don't keep activities' is ON/OFF.

Don’t keep activities is OFF App exited through back press -> User clicks the notification

1729011467780 [stdout] flutter: MyApp - initState()
1729011469676 [stdout] flutter: NotificationsInitializer - init()
1729011469679 [stdout] flutter: NotificationsInitializer - init() - Amplify.Notifications.Push.launchNotification
 = PushNotificationMessage {….}

Home button clicked inside the app -> notification clicked

1729011343009 [stdout] flutter: NotificationsInitializer - Amplify.Notifications.Push.onNotificationOpened.listen(_handleNotification) called

Don’t keep activities is ON App exited through back press -> User clicks the notification

1729010850440 [stdout] flutter: MyApp - initState()
1729010852958 [stdout] flutter: NotificationsInitializer - init()
1729010852962 [stdout] flutter: NotificationsInitializer - init() - Amplify.Notifications.Push.launchNotification
 = PushNotificationMessage {….}

Home button clicked inside the app -> notification clicked

1729010774273 [stdout] flutter: MyApp - initState()
1729010776541 [stdout] flutter: NotificationsInitializer - init()
1729010776542 [stdout] flutter: NotificationsInitializer - init() - Amplify.Notifications.Push.launchNotification
 = null
NikaHsn commented 1 month ago

thank you for providing these details. we will look into it and provide update as we have them.