Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase push notification issue in Android when app is closed/killed

Firebase push does not work on some devices when app is closed with only data payload. See this thread: https://github.com/firebase/quickstart-android/issues/41

I know when app is killed by swipe then some OEM kill all the services of the app which directly effect FirebbaseMessagingService and due to this onMessageReceived() method never invoked. I have also tried with high priority FCM but sadly no success. Here are the phones on which I am facing an issue: OnePlus, Lenovo, Huawei.

Currently, I am testing with OnePlus 5, when I change the battery setting to "Don't Optimise" then push notification started working.

I killed the app and run dumpsys package MY-PACKAGE | grep stopped command and I found that app is not stopped. It shows stopped=false. It means app is running.

The concept of push notification is to notify users when app is closed but currently, we are unable to do.

Any suggestion how can I fix this?

like image 498
Faisal Shaikh Avatar asked Feb 06 '18 11:02

Faisal Shaikh


1 Answers

FirebaseMessagingService can receive PushNotification even when app is closed/killed.

But there are some problems in the way. The behavior of the apps changes between development and production, and because of the device provider.

The first thing you have to consider, is when the app is in development, if you force close the app (kill-process), FirebaseMessagingService stop being triggered. But this doesn't happen in production, so don't be aware of this if your APK is signed. link to source

The second thing, is that there some Android phone providers that manage processes by them selfs. We can see an example like Huawei phones and their "Protected applications", which make user decide if want to protect the app or not. Only famous apps are protected on installation like WhatApp or Twitter... link to source

At this point, your FirebaseMessagingService should be triggered, but there are other problems related with memory and processes managed by system (OS). Your Service can be canceled because of the time that it's spending to handle the PushNotification. You can find many ways to handle this problem, but the best way, is Firebase JobDispatcher. link to source

like image 91
IgniteCoders Avatar answered Nov 03 '22 03:11

IgniteCoders