b8ne / react-native-pusher-push-notifications

Manage pusher interest subscriptions and notification events in Javascript.
MIT License
96 stars 85 forks source link

Opening the app from background triggers 'notification' event with the last opened notification #98

Open hypnocill opened 2 years ago

hypnocill commented 2 years ago

On Android, if I get a notification in app killed or background state, then open the notification - the JS 'notification' listener is triggered with the payload of that notification - so far, so good. But if I minimize the app and open it again (no new notification whatsoever), the 'notification' event is triggered again with the last opened notification.

Seems like the check boolean launchedFromHistory = intent != null ? (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0 : false; in https://github.com/b8ne/react-native-pusher-push-notifications/blob/master/android/src/main/java/com/b8ne/RNPusherPushNotifications/NotificationsMessagingService.java is not working correctly.

I have a Splash Screen (if that might help debug the issue).

Since my notifications might trigger navigation, I had to do a workaround - storing the google message id from the last received notification in the 'notification' event handler and checking if the incoming notification has the same id - if so, don't do anything.

Though I'd prefer to have that managed natively

ferasabufares commented 1 year ago

@hypnocill did you find any solution for this

hypnocill commented 1 year ago

@hypnocill did you find any solution for this

Just the workaround I described in my last comment

ferasabufares commented 1 year ago

@hypnocill can you please share with me full main activity code

i try to add this but my app keep crashing

public class MainActivity extends ReactActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);  // here
        super.onCreate(savedInstanceState);

// what i add ==>
          Intent intent = new Intent(this, MainActivity.class);
        intent.putExtras(getIntent().getExtras());  // Pass along FCM messages/notifications etc.
        startActivity(intent);
        finish();
    }