quickstart-android: onMessageRecieved not working when app is killed. Any solution?
Step 1: Describe your environment
- Android device: Meizu M1 Note
- Android OS version: 5.1
- Google Play Services version:
com.google.gms:google-services:4.2.0
- Firebase/Play Services SDK version:
implementation 'com.google.firebase:firebase-core:16.0.7'
// implementation 'com.google.firebase:firebase-iid:17.1.0'
implementation 'com.google.firebase:firebase-messaging:17.4.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-functions:16.1.3'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.gms:google-services:4.2.0'
Step 2: Describe the problem:
Almost all phones are fine. But in some phone (Meizu M1 note):
onMessageRecieved not working when app is killed in some devices. It works perfect in foreground and in background. But when app is killed I don t receive notification in system tray, or call onMessageRecieved .
I send only DATA (to, data) notification. What I do wrong?
I read #4 , #89 , #86 , #368 , #365 , #337 , #205 , #96 , #20 , #4, #151 , #816 did not find the answer.
I get a strange error in logcat W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=net.korul.hbbft (has extras) }
I made this receiver - but it did not help
<receiver
android:name=".MyBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="net.korul.hbbft" />
</intent-filter>
</receiver>
AndroidManifest contains:
<service android:name=".services.MyFirebaseMessagingService"
android:permission="true"
ndroid:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase. MESSAGING_EVENT"/>
</intent-filter>
</service>
MyFirebaseMessagingService - is standart from snippset
Steps to reproduce:
- Minimize and swipe out your application
- Send FCM notification
- You can see the below log but notification doesn’t trigge
Observed Results:
W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=net.korul.hbbft (has extras) }
Expected Results:
Should get the notification
Relevant Code:
I read all the branches dedicated to this issue, do not refer to them! The problem is, she is over 2 years old! Need a solution!
I also tried to send a push message with the firebase console, and it does not come - the exact same error
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 27 (3 by maintainers)
I was able to solve the problem. In our app we are displaying a splash screen (SplashActivity.java) before the app starts. So when a push notification comes in and I tapped it it opened the app but loaded SplashActivity and not MainActivity. SplashActivity does nothing else than opening MainActivity with an Intent. The problem there was that it didn’t forward the Extras from the Bundle and therefore there never was any payload in MainActivity. Forwarding the payload from SplashActivity to MainActivity solved the problem for me.
Here how it looks like:
@EdwardQuixote that’s a reasonable thing to ask, I was just saying that there’s no need for us to do something like “restart the service” since FCM messages are received by Google Play services and not your app itself. When you use something like Pushy then each app is going to keep its own connection open. So that’s where the different behavior comes from. If every app on your phone had an MQTT connection open in the background your battery would be very unhappy 😃
I have the same issue. Somewhat.
Logcat (app kill):
Logcat (message delivery):
adb shell dumpsys package <package> | grep stopped
:But: After some testing it looks like that
stopped=true
is only the case when I’ve started the app with Android Studio. If I start the app manually or usingadb shell am start -n
and then kill it (swipe from recents) then the state isstopped=false
and push notifications work just fine!@samtstern Why, then, Google will not fix this bug? Accepts push with google service and redirects the receiver in the application. It’s good if all the push messages are handled by one service in the system, and only it keeps one connection for all. And yes, if each application opens the connection it will be bad. But what to do in this situation? Push is required when the application is closed! I don’t like the answer of Google, from the category - we are fine on a pixel and samsung, so leave us alone! This is not an answer! Does not work on many phones!