question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onMessageReceivedCallback works in foreground and background but not if app is closed (e.g. swiped from recents)

See original GitHub issue

The onMessageReceivedCallback handler works just fine when the app is running in foreground or when I minimize it. Whenever I close it, for example by swiping it from the recents, it will not work anymore.

When it’s in this state the only notifications that come through (to the tray) are these kind:

notification: {
  title: 'Title',
  body: 'Body'
}

But what I need is this:

data = {
  messageId: '1519656340496',
  userId: 'USER_ID',
  date: '1519656340496',
  text: 'Text Message',
  type: 'message',
  messageCollectionId: 'messages',
  channelId: 'CHANNEL_ID',
  displayName: 'USER_NAME'
}

However the app only receives them after launching the app.

This line is already active in the include.gradle file:

compile "com.google.firebase:firebase-messaging:$firebaseVersion"

Both services are enabled in AppManifest.xml:

<service android:name="org.nativescript.plugins.firebase.MyFirebaseInstanceIDService">
  <intent-filter>
    <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
  </intent-filter>
</service>
<service android:name="org.nativescript.plugins.firebase.MyFirebaseMessagingService">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
  </intent-filter>
</service>

onMessageReceivedCallback is initialized directly in the .init() function in app.js. I’m sending to a topic which the user subscribes to when he logs in.

Other things that might be useful to know for debugging: I’ve also added these parameters

android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop"

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KkevinLicommented, Jun 26, 2018

@erkanarslan I do not believe this is true. Using the Quickstart Android demo (https://github.com/firebase/quickstart-android/blob/master/messaging/README.md) I am able to get onMessageReceived() even after swiping the app and from there I can build local notifications to show the user.

On the other hand, even with the latest 6.20 nativescript plugin, onMessageReceived() will not be called for me once I swipe the app. My manifest is identical to the one from Android Quickstart and get the same behavior as @trashbytes.

@EddyVerbruggen Is this the expected behavior and if so why does it deviate from original FCM behavior? I have replicated this using the demo and a new app with the plugin installed. Devices used : s8, One plus 3T, Pixel and a Moto on OS versions 24 & 26.

0reactions
gustavost26commented, Jun 24, 2022

Still don’t have any concrete solution to this problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase onMessageReceived not called when app in ...
If your app is in the background or closed then a notification message is shown ... On Android platform, data message can work...
Read more >
Does swiping from recent app screen kill the foreground ...
Yes, this clear the App from the RAM(memory). This is valid from the Android 5.0+. The foreground services are definitely stopped if executing....
Read more >
nativescript-plugin-firebase - Bountysource
onMessageReceivedCallback works in foreground and background but not if app is ... I close it, for example by swiping it from the recents,...
Read more >
Receive messages in a JavaScript client - Firebase - Google
Handle messages when your web app is in the foreground ... but in background cases you may also need to handle onBackgroundMessage or...
Read more >
Foreground service killed when receiving broadcast after ...
Swipe the app away in the Recent Apps list ... I believe #3 is spot on what is going on and #1 workaround...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found