react-native-push-notification-CE icon indicating copy to clipboard operation
react-native-push-notification-CE copied to clipboard

[Android] When receiving a remote notifications the app opens

Open senne-af opened this issue 6 years ago • 6 comments

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.

senne-af avatar Jun 29 '18 13:06 senne-af

check this https://github.com/bhram/RNPowerManagerBridge

bhram avatar Jul 11 '18 18:07 bhram

Hey @bhram, I don't see how that solves the problem.

senne-af avatar Jul 20 '18 16:07 senne-af

Experiencing this as well. @sennevc were you ever able to find a solution?

Steps to reproduce on Android:

  1. Schedule a notification using PushNotification.localNotificationSchedule.
  2. Kill the app (background and then swipe app away in recent apps list)
  3. When notification appears, app will reopen.

mattpetrie avatar Aug 13 '18 19:08 mattpetrie

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.

senne-af avatar Aug 14 '18 11:08 senne-af

@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()
}

mattpetrie avatar Aug 15 '18 23:08 mattpetrie

@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.

likern avatar Dec 15 '18 23:12 likern