React-native-onesignal: App rerender after click on push notification

Created on 5 Jan 2019  ·  30Comments  ·  Source: OneSignal/react-native-onesignal

Description:
When I clicked on push notification, my Android app is getting render again. I didn't check it on IOS.

Environment
react-native-onesignal: 3.2.11,
react: 16.6.0-alpha.8af6728,
react-native: 0.57.4,

I used npm install --save react-native-onesignal command to install oneSignal.

I configured the oneSignal package according to this documentation. https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup

Steps to Reproduce Issue:

  1. Install the OneSignal SDK using npm into your project
  2. Initialize the SDK in the Android
  3. Send a push notification throught OneSignal webSite(for testing purpose).
  4. App is running in foreground.
  5. Clicked on the push notification received.
  6. App is render again.

I'm using react-navigation: 2.16.
This is my code.

componentDidMount() {
        // One signal notification settings
        OneSignal.configure();
        OneSignal.setLogLevel(5, 0); // adb logcat debug (5) logs
        OneSignal.init('xxxxxxxxxxxx');
        OneSignal.inFocusDisplaying(2);
        OneSignal.addEventListener('ids', this.onIds);
        OneSignal.getPermissionSubscriptionState((status) => {
            if(status.userId)
                // update userID using props
    });
    }
    onIds = (device) => {
        const userId = device.userId;
        if(userId)
           // update userID using props

        OneSignal.removeEventListener('ids', this.onIds);
    }



md5-e56be07ed32a6f3a60c846daed91829f



        OneSignal.addEventListener('received', this.onReceived);
        OneSignal.addEventListener('opened', this.onOpened); 

I try to find out a solution, But I couldn't. If some has any idea about this Please tell me.

Most helpful comment

@rgomezp :
Thanks for the response.
I think as you mention in previous comment that you guys are planning for a fix. Till that we will wait.

All 30 comments

I find out, why app gets rerender. Because when I clicked on notification, app goes to background and then it comes to foreground.
why does app status change? when I clicked on notification.
How to stop this.

Did you add android:launchMode="singleTop" to your AndroidManifest.xml?

@martinosmartinos yes, I added it.

Try to move your logic into componentWillMount lifecycle instead and see if it helps.

Thanks for your support @martinosmartinos. But it didn't work.

Hello @janaka120
It sounds like you're trying to deep-link into your app. You can find more information on this topic here. You may also be encountering an issue due to react-navigation.

I'm wondering if the entire app is re-rendering or if you mean that the current screen gets re-rendered (react-lifecycle)?

Hi @rgomezp

My entire app is rendering when I tap on push-notification.

@janaka120 I see. Is the metro-bundler rebuilding everything or do you simply get taken back to the splash-screen and/or homepage?

@rgomezp I don't get back to the splash-screen. I get back to the homepage. When I console my main app.js after tap on push notification, it rendered So my app route to home screen.

@janaka120 ok so just to confirm, the app is not being re-bundled correct?

@rgomezp yes. It's not rebundling.

This sounds like a deep-linking issue. Please read our documentation on setting deep-links correctly and verify that you did everything correctly. https://documentation.onesignal.com/docs/links

@rgomezp I didn't use any deep-link with push-notification.

Can you please test on iOS to see if you are getting the same result? I'm not sure why this is happening. React will re-render when state changes

Closing due to no response

That could solve your problem:
Instead of using android:launchMode="singleTop"use android:launchMode="singleTask"

That could solve your problem:
Instead of using android:launchMode="singleTop"use android:launchMode="singleTask"

i have same issue.
another problem is when i open deep link from Email, apps open new app task. If i open task manager my apps have multiple tabs running.
And it solved if i change to SINGLETASK.

But my question, is there any problem that i must concern if change to SINGLETASK??

@rgomezp I believe I'm experiencing the same problem as the original poster on Android. My application is running, and I minimize it. A push notification arrives, and I tap it to open the application. At this point, the entire application reinitializes. It does not behave this way on iOS. I am currently using singleTop as recommended by the SDK docs, but I'm curious if another mode might fix this problem.

Use singleTask instead.
I don't understand why they're not fix this issue, because this is very important

Thanks @hotaryuzaki, after posting my comment yesterday I tried out singleTask which seems to be working so far without any noticeable problems. I am concerned though because the SDK authors have said multiple times that this could cause issues.

Yes I got confirmed by them about that, but they weren't mentioned the detail which problem they mean.
If it was an issue, I don't know why they're didn't fix that.

Howdy,
We are planning to fix this in a future release. Thanks for your patience

@rgomezp : Can you provide possible issue detail that may occure on changing launchMode from 'singleTop' to 'singleTask'.
So we can understand risk of switching to 'singleTask'
I am also facing an issue with auth0 and onesignal.

Right now I had swithed to 'singleTask'

Setting it to singleTask may result in multiple copies of your activity being created

@jariwalabhavesh

@rgomezp :
Thanks for the response.
I think as you mention in previous comment that you guys are planning for a fix. Till that we will wait.

@rgomezp As per React Native documentation (https://facebook.github.io/react-native/docs/linking) Linking requires the MainActivity to be singleTask. Is there away around this for OneSignal?

Howdy,
We are planning to fix this in a future release. Thanks for your patience

@rgomezp Thank you for working on this and is this issue fixed yet?

This feature request has not been implemented yet

@rgomezp is there an ETA for when the fix will come through? IMO: This is the biggest problem with onesignal for react native in its current state.

I have also switched to singleTask.

I am not seeing multiple copies of the activity being created when using singleTask. Plus it is the only way to stop the app from re-launching on notification press. It is also necessary to have deep links work properly...

Having same problems with push notifications on android. But I do use deep links.
The problem is that if app is killed and opened from notification it open from loading everything from start. If user pressed Home button and comes back again app always reloads and always re-launches same launchUrl from depp-linking.

Was this page helpful?
0 / 5 - 0 ratings