Darolți Dan
Darolți Dan

Reputation: 59

Handle dismissed Firebase notification in Android System Tray

In the onMessageReceived method I'm saving some data in the local database.

If the app is in background when I tap on the notification, it redirects me to the launcher activity. There I'm processing the incoming data from the Bundle and save it in the local database.

How can I handle when the user dismisses the notification? Because if the user dismisses the notification the data I receive from the server is lost.

Upvotes: 1

Views: 1829

Answers (4)

PEHLAJ
PEHLAJ

Reputation: 10126

1. You can directly save data to local db in onMessageReceived rather than waiting for user to open notifications.

2. Disable the auto-cancel

notication.setAutoCancel(false)

Upvotes: 0

Darolți Dan
Darolți Dan

Reputation: 59

It was fixed when removing the notification and used DATA method for fcm.

thank you @DivyeshPatel

Upvotes: 1

Sajal Gupta
Sajal Gupta

Reputation: 146

You can handle the dismissal by adding deleteIntent to your notification builder. use the intent, add data that you received to it and redirect it to the handler class. In the handler class extract data and save to db :)

mBuilder.setDeleteIntent(PendingIntent.getService(this, 0, new Intent(this.context, YourHandlingClass.class), PendingIntent.FLAG_CANCEL_CURRENT));

Upvotes: 1

AKSHAY MANAGOOLI
AKSHAY MANAGOOLI

Reputation: 130

You can use BroadCast Reciever to save data when it is received check out this link:https://developer.android.com/guide/components/broadcasts.html

Upvotes: 1

Related Questions