Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onOpened and onReceive not firing #606

Closed
burdell opened this issue Aug 17, 2018 · 25 comments
Closed

onOpened and onReceive not firing #606

burdell opened this issue Aug 17, 2018 · 25 comments

Comments

@burdell
Copy link

burdell commented Aug 17, 2018

Description:
I've upgraded from 3.2.5 to 3.2.6 which resolved #583, but still can't get the onReceived and onOpened functions to fire when app is minimized. The functions do fire if app is completely shut down. Confirmed its working on iOS.

I've tried yarn remove/yarn add and react-native unlink/react-native link but still not seeing it working

Environment

Steps to Reproduce Issue:

  1. Start app on Android
  2. Minimize app
  3. Trigger push notification
  4. Open app by clicking push notificaition. No event fired
  5. Quit app completely
  6. Trigger push notification
  7. Open app by clicking push notificaition. Event fired
@pacozaa
Copy link

pacozaa commented Aug 20, 2018

+1

@pacozaa
Copy link

pacozaa commented Aug 20, 2018

I have to go back to 3.2.4

@burdell
Copy link
Author

burdell commented Aug 20, 2018

@pacozaa Did going back to 3.2.4 work for you? I still am seeing the same issue.

After doing more research I've found that if the initial notification happens from when the app is totally shut down, any notifications received when the app is minimized cause the handlers to fire.

But if I start the app, minimize without receiving a notification, the handlers are not fired when a notification comes in

@Nightsd01
Copy link
Contributor

Nightsd01 commented Aug 20, 2018

@burdell I followed your steps to reproduce, but it works for me every time. Are you certain you tested on 3.2.6...? How do you know these handlers are not firing?

Can you test out our demo project with 3.2.6 and tell me if the issue occurs?

@pacozaa
Copy link

pacozaa commented Aug 22, 2018

@burdell yes it is.

@steverob
Copy link

@Nightsd01 how do you run the demo project?

@Nightsd01
Copy link
Contributor

@pacozaa It's in the examples/RNOneSignal folder. You can run yarn, then run react-native link react-native-onesignal.

Once that's done, you should be able to just replace with your App ID in index.js and should be able to run the project. You can try modifying the SDK versions and so on to match what you are using in your real app.

Please let me know if you can reproduce this issue in our demo project or not - as of now I have not been able to reproduce this and 99% of the time it is user error - but it's possible it's a bug that only effects certain versions/devices as well.

@burdell
Copy link
Author

burdell commented Sep 18, 2018

Sorry, been away from this for a few weeks but I was able to verify that it was working in the demo app

Couldn't ever get it to work in our app though even after going through and trying to copy how the demo app was setup 🤷‍♂️

@mcmar
Copy link

mcmar commented Sep 19, 2018

I'm seeing different, but related behavior to what's described here on Android (3.2.7)
1, Foreground: onOpened/onReceived fire correctly
2, Background: onOpened/onReceived fire correctly
3, Dismissed (swiped-away from multitask switcher): onOpened/onReceived do not fire

On iOS, all of 1, 2, and 3 work correctly.

I am able to reproduce this behavior in the demo app on react-native-onesignal@3.2.7, which leads me to believe that this may be a recent regression on Android. Possibly related to the recent fixes for background?

@akos-bako
Copy link

I was experiencing the same issue as @burdell, but I managed to solve it.

On iOS, everything worked flawlessly. But OnOpened wouldn’t fire on Android if the app was in inactive (background or killed). I’ve experienced that it usually fires once every session, but once it’s put in the background again, and tap on a new notification, it just shows the app. What I found weird is that there are two instances of my application after I tapped on the notification.

  1. react-native run-android
  2. app cold starts (main instance)
  3. press home button to put app in background
  4. trigger & tap on new notification
  5. onOpened IS called, but the app cold starts, despite the fact it was running 10 seconds before
    NOTE: if i check my recents I have two instances of the application
  6. press home to put app in background (new instance disappears from recents)
  7. trigger & tap on new notification
  8. onOpened is NOT called, app cold starts again
    NOTE: in the recents there is only a single instance

I suspected this behaviour could be the root of the issue, and all I had to do to fix this is to modify the AndroidManifest.xml from:

<activity
        android:name=".MainActivity”
        android:launchMode=“singleTop”
        >

to:


<activity
        android:name=".MainActivity”
        android:launchMode="singleInstance"
        >

After this, everything works perfectly on Android. I’m not sure why the example uses singleTop.

What I did:

I'm using:
"react-native": "0.55.4",
"react-native-onesignal": “3.2.7”


@Nightsd01
Copy link
Contributor

@mcmar Some android device makers will not allow your app to execute received callback if the app has been intentionally dismissed/terminated by the user. That would explain why the received callback didn't work for you - but you are also saying opened didn't work as well?

9/10 times when a user reports this issue it is because they have a bug in their code inside of the callback, or it's because of their launchmode/view hierarchy has an issue. We have not seen a user that has been able to reproduce in our example project.

When you reproduce in our example project, can you please zip up the project exactly as it was when you reproduced and post a link here?

Can you also post more information such as a logcat when you open the notification for the first 15 seconds? Can you also tell us what version/s of android you are able to reproduce this issue on?

@aldoetobex
Copy link

I've found how to solve this problem.
I use latest version of react-native-onesignal.

Just delete 2 lines below :

@OverRide
public void onHostDestroy() {
//OneSignal.removeNotificationOpenedHandler();
//OneSignal.removeNotificationReceivedHandler();
}

I have compared the previous version with the current version and viola! that's where the main problem is.

@p-ugulino
Copy link

p-ugulino commented Oct 27, 2018

I also have the same problem.
I've tested with samsung devices and android 7 or lower and everything is fine.
Though when I test on a Motorola with android 8 it doesn't work.

@Nightsd01 would you have any idea why this might happen?

Thanks

@meetyourdev
Copy link

I was experiencing the same issue as @burdell, but I managed to solve it.

On iOS, everything worked flawlessly. But OnOpened wouldn’t fire on Android if the app was in inactive (background or killed). I’ve experienced that it usually fires once every session, but once it’s put in the background again, and tap on a new notification, it just shows the app. What I found weird is that there are two instances of my application after I tapped on the notification.

  1. react-native run-android
  2. app cold starts (main instance)
  3. press home button to put app in background
  4. trigger & tap on new notification
  5. onOpened IS called, but the app cold starts, despite the fact it was running 10 seconds before
    NOTE: if i check my recents I have two instances of the application
  6. press home to put app in background (new instance disappears from recents)
  7. trigger & tap on new notification
  8. onOpened is NOT called, app cold starts again
    NOTE: in the recents there is only a single instance

I suspected this behaviour could be the root of the issue, and all I had to do to fix this is to modify the AndroidManifest.xml from:

<activity
        android:name=".MainActivity”
        android:launchMode=“singleTop”
        >

to:


<activity
        android:name=".MainActivity”
        android:launchMode="singleInstance"
        >

After this, everything works perfectly on Android. I’m not sure why the example uses singleTop.

What I did:

  • I used the example app as a template in my project
  • I set up the redux rehydration to make sure everything happens after the store is set up (as seen here #332 (comment) )
  • Change to singleInstance

I'm using:
"react-native": "0.55.4",
"react-native-onesignal": “3.2.7”

This did not work for me.
When app is in background i.e app is minimized and in memory, OpOpened does not fire. This happens only in Oreo and above. The notification when clicked on it, the app takes about 10-20 seconds to launch.

@udarts
Copy link

udarts commented Nov 27, 2018

Hi all,

I am having a similar issue. On both iOS and Android, when I receive a push notification, I click on the notification and it opens the app. I created a code that when the app opens and it checks if there is a push notification, then opens a different screen to display the notification.

Now the issue is, that the first time when I click on the notification the app opens, but nothing happens after that. Then closing the app, reopen it and suddenly the screen appears with the notification text shown.

So is the onOpened function not working the first time? This happens on iOS and Android.

@rgomezp
Copy link
Contributor

rgomezp commented Apr 16, 2019

@meetyourdev @udarts ,
Are you still having this issue?

@rgomezp rgomezp closed this as completed Apr 24, 2019
@mauricioalexandres
Copy link

Any answers to the problem?

@samitha9125
Copy link

This still happens. Any solution?

@samitha9125
Copy link

OnReceived is still not firing when app is background. Any solution?

@rgomezp rgomezp reopened this Apr 21, 2020
@rgomezp
Copy link
Contributor

rgomezp commented Apr 21, 2020

Howdy,
We haven't been able to reproduce this issue. Does anyone have an example project we could test with?

@samitha9125
Copy link

@rgomezp I’m sorry. This does not happen always but when several notifications come to the mobile or when app was in background for few hours this happens. On both iOS and Android. This doesn’t happen always but regularly.

@rgomezp
Copy link
Contributor

rgomezp commented Apr 22, 2020

@samitha9125 ,
The received event only fires if the app is in foreground. Take a look at our "events" section from our documentation .

@mauricioalexandres ,
Can you provide some details regarding your specific implementation?

@samitha9125
Copy link

@rgomezp Oh thank you for that. I didn’t see that earlier. So how can I get incoming notifications when my app is in the background?

@rgomezp
Copy link
Contributor

rgomezp commented Apr 27, 2020

Howdy,
We have a section describing how to implement Background Notifications. I'll close the issue since this isn't really an ongoing issue. Also, consider reaching out through our official OneSignal.com support channel for quicker support.

Enjoy!

@rgomezp rgomezp closed this as completed Apr 27, 2020
@eskiesirius
Copy link

Hello.. i know this is an old issue but can you guide me? I already created an incoming call screen but the problem is that the incoming call screen wont display when the app is inactive.. so is there other way to display it even it is inactive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests