react-native-push-notification-CE
react-native-push-notification-CE copied to clipboard
[Android] When receiving a remote notifications the app opens
When the app is killed (not in background) and it receives a remote notification, it displays the notification but also opens the app. This is bad practice and very intrusive for the user.
However, when the app is in background, the notification shows, but the app does not open.
check this https://github.com/bhram/RNPowerManagerBridge
Hey @bhram, I don't see how that solves the problem.
Experiencing this as well. @sennevc were you ever able to find a solution?
Steps to reproduce on Android:
- Schedule a notification using
PushNotification.localNotificationSchedule
. - Kill the app (background and then swipe app away in recent apps list)
- When notification appears, app will reopen.
Hey @mattpetrie,
I did some more research and found out that the issue was caused by a conflict between this library and react-native-navigation.
You can read more on it in these threads:
- https://github.com/zo0r/react-native-push-notification/issues/470
- https://github.com/wix/react-native-navigation/issues/566
Unfortunately, I didn't find a solution yet and will probably switch to react-native-notifications as soon as android 8 is supported.
@sennevc Thanks! Your reply set me on the right path to get this fixed. This comment mentions this page in the react-native-navigation docs. It's terribly titled -- it really should be called "Handling App Launching in the Background on Android", because that's what it's really about.
Adding the code from there (with one minor modification) to our index.js fixed the issue with the app launching. Posting the full snippet in hopes it helps you too:
import { AppState } from 'react-native'
import {Navigation, NativeEventsReceiver} from 'react-native-navigation'
if (Plaform.OS === 'android') {
Navigation.isAppLaunched().then(appLaunched => {
if (appLaunched) startApp())
new NativeEventsReceiver().appLaunched(() => {
if (AppState.currentState === 'uninitialized') startApp() // this ensures the app doesn't relaunch if it's already in the background.
})
} else {
startApp()
}
@sennevc Thanks! Your reply set me on the right path to get this fixed. This comment mentions this page in the react-native-navigation docs. It's terribly titled -- it really should be called "Handling App Launching in the Background on Android", because that's what it's really about.
Adding the code from there (with one minor modification) to our index.js fixed the issue with the app launching. Posting the full snippet in hopes it helps you too:
import { AppState } from 'react-native' import {Navigation, NativeEventsReceiver} from 'react-native-navigation' if (Plaform.OS === 'android') { Navigation.isAppLaunched().then(appLaunched => { if (appLaunched) startApp()) new NativeEventsReceiver().appLaunched(() => { if (AppState.currentState === 'uninitialized') startApp() // this ensures the app doesn't relaunch if it's already in the background. }) } else { startApp() }
@sennevc @mattpetrie Sorry, I don't use react-native-navigation
. But I'm experiencing the similar issue. My application (when it is in background) moves to foreground if I tap notification action "Complete". The onNotification
callback is called and does nothing, but anyway this doesn't help.
Is this related to your cases? I need to perform some stuff in this onNotification
callback, but without bringing application to foreground. Just want to complete task and don't show application in foreground.