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

Tapping a notification in the notification centre can result in app being relaunched! #281

Closed
npomfret opened this issue Nov 11, 2016 · 15 comments

Comments

@npomfret
Copy link
Contributor

To reproduce:

  1. Send an Android notification that does not contain a data element while the app is running in the background.

  2. Tap on the notification in the notification centre.

  3. Repeat a few times.

What I noticed is that when tapping the notification my app appeared to re-launch itself even though it was already running. After trying a couple of times I realised that the app was launching multiple copies of itself - each tap resulted in a new instance of the JS app... but only 1 runtime - so I have multiple apps running side by side with a single UI!

It does not appear to happen if the push notification contains a data element.

@TriangleIL
Copy link

I'm having this same exact issue. Considering moving to a "data" payload, but would prefer to stay with the "notification" payload if at all possible. Any thoughts around this one?

@jk94
Copy link

jk94 commented Jan 5, 2017

@npomfret i'm having the same issue too. But i can't fix it with a data attribute. Am I doing it wrong? Can you show me how you fixed this?

@npomfret
Copy link
Contributor Author

npomfret commented Jan 5, 2017

I've not fixed it. @mikelambert have you any idea what's happening here?

@mikelambert
Copy link
Contributor

mikelambert commented Jan 9, 2017

So without a data payload, the onMessageReceived will get called when opening the notification. And this is where my changes get run, so it's likely related to my code. :( How are you verifying that there are multiple "apps" running, and what does that mean exactly?

This might be fixed by switching to headless tasks added in RN 0.36. Are we perhaps willing to break compatibility with RN versions older-than-that at this point? I'm focused on other things at the moment for the next couple months, but can do the migration the next time I dig into the mobile/notification code.

Alternately, comparing the Headless JS code and the RN-PN code developed independently, it looks like the only thing I had forgotten was the wake-lock (I think unrelated) and the listener-removal (maybe multiple identical listeners are the source of the problems?)

@jk94
Copy link

jk94 commented Jan 11, 2017

@npomfret @mikelambert thanks for your answers. I fixed my problems with an attribute in my AndroidManifest.xml. I added android:launchMode="singleTop" to the main activity element.

<activity
   android:name=".MainActivity"
   android:label="@string/app_name"
   android:launchMode="singleTop"
   android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
   ...
</activity>

Maybe this helps s.b. else!

@npomfret
Copy link
Contributor Author

@mikelambert sorry for the slow reply, been travelling. I like your theory about the listener removal.

Have you tried replacing your code with the built in RN headless tasks?

@mikelambert
Copy link
Contributor

Nope. Please see the second paragraph of my message above. :p

@Noitidart
Copy link

The deep linking docs recommend "singleTask" - https://facebook.github.io/react-native/docs/linking.html -

I havent tried the push notification module yet. But does anyone know how that compares to with @jk94 approach above of android:launchMode="singleTop"?

@fadilhim
Copy link

Hi i'm currently having this issue, when app is in background and show localnotification it launch the app when i clicked on notification.
Is there any way to prevent app from launc ?
I'am using react-navigation

@Dallas62 Dallas62 closed this as completed Aug 4, 2020
@raymatos
Copy link

raymatos commented Nov 6, 2020

Why was this closed? What was the solution?

@mahipalsingh-syt
Copy link

@raymatos issue still there with local notification in android , onNotification is not working...

@Dallas62 why this query has closed ? :(

@nikolajskov
Copy link

@Dallas62, what is the solution that fixes this issue?
I'm still seeing the issue with version 7.3.1. I've tried the solution suggested by @jk94 with using android:launchMode="singleTop" and it seems to fix the problem. Is this the correct solution?

@Dallas62
Copy link
Collaborator

Hi @nikolajskov
This is the correct solution to avoid this issue.

@nikolajskov
Copy link

Thanks @Dallas62

@redefinered
Copy link

redefinered commented Jul 29, 2021

I ran into this issue but with different setup. My app is not invoking the onNotification func because I have react native splash screen installed which modifies android main activity and that means the data that comes from notification library does not reach the react activity.

This post has a fix in this particular scenario:

crazycodeboy/react-native-splash-screen#289

I hope that helps anyone!

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

No branches or pull requests