Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app not receiving Firebase Notification when app is stopped from multi-task tray

I have read a similar question on SO, however, I was not able to get the correct answer from it.

I have a system wherein we send notification to around 500 devices.

Unfortunately, many of these devices are not receiving the notification. I have found that OPPO F1 series phones are particularly not getting the notification.

I have observed that this occurs if the app is stopped from multi-task tray. How do I resolve this?

Update: I have observed that when I close the app from task-tray, my app is forced stop in application manager. While when I close Whatsapp from task-tray, it is still not forced stop. How is that being handled by Whatsapp?

like image 519
milan m Avatar asked Sep 15 '16 06:09

milan m


People also ask

Is there a limit for Firebase notifications?

You can send up to 240 messages/minute and 5,000 messages/hour to a single device.

How do I get Firebase to push notifications?

Go to Firebase console — →Project Settings — →Cloud Messaging. To send the message select Body — →Raw — →JSON(application/json). You can send Notification Payload , Data Payload and even both using POSTMAN service.

Can FCM notification on Android overwrite previous one?

It's possible. Two approaches. First is you make use of the collapse_key parameter to set the message as a collapsible message.


2 Answers

Update 03/2017 - Including a part of my answer here.

For the topic with regards to swipe closed/killed/force stopped, this topic has been discussed for quite some time and there doesn't seem to be a definite answer. During one of my testings, I am able to still receive a message (tested with a data-only message payload) if I Swipe close my app. But when I force closed it from the Settings menu, I wasn't able to receive any messages. Do note that this is not always the behavior.

There are some devices that were designed that when you swipe close the app, it will be the same as force stopping them (see my answer here).

There are also devices where even if the app is still just simply swiped away, even though it's not force closed, the device itself is preventing it from receiving messages. Others say that this can't be the case because apps like WhatsApp were able to do it. The reason I've learned so far for that is because the device manufacturers have whitelisted most of the well-known apps for it to be possible.

This is not documented anywhere because (IMO), this is a topic that depends also on the device and that FCM has no total control over.


Original Answer:

Since it's device specific (as you mentioned in your post: OPPO F1 series phones), it may very well be possible that when an app is stopped from multi-task tray in that device, it is actually killing the app, causing the services and other background processes associated with it to also be destroyed. See this answer for a little more idea of what I'm trying to say.

If you search around the community, what is commonly suggested here is to make use of the START_STICKY flag. However, I've seen that it was previously mentioned before for FirebaseMessagingService (see this post, comment by @ArthurThompson):

These services will be started by Google Play services, which is always running on the device. You don't have to and should not start/stop these services yourself.

With that said, there is also the possibility of (again from the comments):

There may be a setting on the device that allows/disallows this.


I suggest doing further testing if the services are being killed by the device itself or see if there are settings that are blocking the notifications.

like image 101
AL. Avatar answered Nov 09 '22 14:11

AL.


Have you tried to use stopWithTask attribute on your service class?

<service
    android:name="com.yourapp.YourPushService"
    android:stopWithTask="false" />

If set to true, this service with be automatically stopped when the user remove a task rooted in an activity owned by the application. The default is false.

If the flag is false, there is an onTaskRemoved callback in your Service class.

In the case you can detect the "swipe" event, and you can implement a workaround.

like image 44
danesz Avatar answered Nov 09 '22 15:11

danesz