Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotificationAppLaunchDetails returning true even after the app launch from recents. #1926

Open
arv-aks opened this issue Mar 15, 2023 · 9 comments

Comments

@arv-aks
Copy link

arv-aks commented Mar 15, 2023

void checkIfTheAppIsOpenedFromNotification() async {
final NotificationAppLaunchDetails? notificationAppLaunchDetails =
    await NotificationService.flutterLocalNotificationsPlugin
        .getNotificationAppLaunchDetails();

NotificationResponse? response;

if (notificationAppLaunchDetails != null) {

  //check if the app is launched from the notification

  if (notificationAppLaunchDetails.didNotificationLaunchApp) {
    print("app launched from notification");

    //check if the notification contains the reponse or not
    if (notificationAppLaunchDetails.notificationResponse != null) {

      response = notificationAppLaunchDetails.notificationResponse;
      //check for the response or payload

      if (response != null && response.payload != null) {
        //navigate...

      } else {}
    }
  } else {
    print("app not lauched from notification....");
  }
}
  }

-> When the app is killed and tap on notification -> The app is opened and notificationAppLaunchDetails.didNotificationLaunchApp = true. Thats working fine.
-> When the app is in memory (i.e. background) and I opened other apps. After sometime I click on this app icon to launch. Then the app restarted (from recents) and the value of notificationAppLaunchDetails.didNotificationLaunchApp = true. Which should be false, because the app is not opened from notification and the payload is also receiving which is the payload of previous notification

@MaikuB
Copy link
Owner

MaikuB commented Mar 16, 2023

What you've described is still working as expected as the purpose of the method is to find out if was launched/started from a terminated state by a notification. This did happen from what got described but the app wasn't terminated again in the scenario. It was put in the background and you resumed the app by using the recents screen so the fact that it reported that a notification was used to start the app still remains true

@arv-aks
Copy link
Author

arv-aks commented Mar 17, 2023

@MaikuB
But I'm navigating to another screen when the app opened from notification but currently it's also navigating to another screen every time app restarting from background. How to resolve this?
// If somehow we can clear the cache of previous notification???

@arv-aks arv-aks changed the title NotificationAppLaunchDetails not working as expected. NotificationAppLaunchDetails returning true even after the app launch from recents. Mar 17, 2023
@myselfuser1
Copy link

This will help https://www.youtube.com/watch?v=aQTvI8L-mZs

@MaikuB
Copy link
Owner

MaikuB commented Mar 17, 2023

@arv-aks I would suggest monitoring the app lifecycle events to help track that changes in the app or that you maintain state that you've dealt with the event. Was thinking recently to add a parameter that allows specifying if it should be consumed or not that would solve your issue. It would be something part of the current 14.0 prerelease and I'm happy to take a PR on this if you can help out on implementing this

@MaikuB
Copy link
Owner

MaikuB commented Mar 20, 2023

Would you also be able to provide a video that shows how this issue could be reproduced using the example app? I remembered there's a check on if the app was launched from recents at

so seems strange this even happens to you

@arv-aks
Copy link
Author

arv-aks commented Mar 24, 2023

I'll provide a video asap. And yes the launchedActivityFromHistory is present.
I tried to implement a method for checking if the app is opened from recents or from notification. I also used launchedActivityFromHistory but still this method is giving me true with previous notification payload data.

@MaikuB
Copy link
Owner

MaikuB commented Mar 24, 2023

Notewhat you tried to implement isn't what I was referring to. I was talking about the general app lifecycle, which is different to tracking how an app was launched. Another approach is your own app could track that a notification was processed to avoid reprocessing it again. As mentioned before at #1926 (comment) you are welcome to submit a PR to the plugin itself

@mdAlvarenga
Copy link

@MaikuB Hi, with my team we had the same issue. The history launchedActivityFromHistory is not enough because of this:

Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY is only set if Android creates a new instance of your activity when the user selects the app from the list of recent tasks. In most cases, this will be when the user starts your application again (from the beginning) after all your activities have finished.

We developed a fix for this issue but we can't push it, can you help us with this?

@artahc
Copy link

artahc commented Feb 29, 2024

This issue also happens when doing hot restart.
Step to replicate:

  • Show notification
  • Close app with back button so the program doesn't get terminated
  • Open app with notification
  • Check didNotificationLaunchApp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants