globocom / react-native-ua

React Native module for Urban Airship
MIT License
37 stars 33 forks source link

on_notification not triggered when app in background in android #52

Open itsrifat opened 7 years ago

itsrifat commented 7 years ago

I have set up the project for both ios and android. onNotificationOpened and onNotificationReceived works fine for android, but nothing happens if the app is in background. For ios, on_notification gets triggered in background if the background processing flag is turned on for a message in Urban Airship. Am I missing something?

itsrifat commented 7 years ago

I did some digging around and looks like Line 24 of ReactNativeUAReceiver.java is always returning false when the app is in background, an hence ReactNativeUAEventEmitter's sendEvent is not getting triggered.

If I comment out the isRunning check on line 26,

if (ReactNativeUAEventEmitter.getInstance() != null) // instead of if (isRunning && ReactNativeUAEventEmitter.getInstance() != null) 

My on_notification code on the js side gets executed fine whether the app is in background or foreground.

Is there any way around this?

@arthursz, Any thoughts?

rlepinski commented 7 years ago

@itsrifat It looks like react only gets setup from an activity. Thats not always going to happen when an Android application is woken up in the background, so the react context will not be setup. This seems to be a limitation with react and not this plugin.