OneSignal / OneSignal-Android-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native Android or Amazon app with OneSignal. https://onesignal.com
Other
591 stars 368 forks source link

[question]: I close the app and open it again and push notifications are auto-generated in my app. #2092

Closed RuHuaytaMars closed 1 week ago

RuHuaytaMars commented 1 month ago

How can we help?

When I close the app and open it again, the notifications are generated again, such as correctly controlling that the push is not generated again if the backend is no longer sending me anything.

Code of Conduct

RuHuaytaMars commented 1 month ago

photo_5069318705577569127_w

**Auto regenerated notifications on.

jkasten2 commented 1 month ago

@RuHuaytaMars when you close your app do the notifications disappear from the Notification Shade? (This happens if the app is "force stopped") If this is the case then OneSignal restores the notification as they end-user never interacted with it, this way they don't miss the notification. If the end-user swipes away the notification or taps on it it should not restore.

RuHuaytaMars commented 1 month ago

Correct, what happens is that the flow of my application is an app for taxi services, that is, for each tracking status a notification is displayed whether the customer interacts with the notification or not, it disappears when it changes status as it could do so that when changing the status that push no longer appears.

jkasten2 commented 1 month ago

... it disappears when it changes status as it could do so that when changing the status that push no longer appears.

By the notification disappears is that your code is dismissing the notification? If so, make sure you use OneSignal.Notifications.removeNotification(id) so the OneSignal SDK knows that your app indented for notification to be dismissed, so it won't restore it.

If you don't want to display the notification if it arrives late (such as the device losses connection) I recommend setting a short TTL on the notification. The TTL is also respected in the notification restore logic too.

If there are other scenarios not covered above you can setup the OneSignal Android Notification Service Extension so you can control if the notification will show based on any logic you wish.