Android Question Firebase notifications during sleep

marcick

Well-Known Member
Licensed User
Longtime User
Many customers are telling me this issue, so I think it is related to some "battery optimization" features in recents Android versions because everything was working fine before.
After a couple of minutes the device is in sleep, it does not receive Firebase notifications. As soon it is waked up, then it shows (I mean notifications are not lost, but just not displayed during sleep).
If I put the device in sleep again it can receive notifications, but after a couple of minutes it stops.
I did another test:
Send a notification to the device (in sleep) and nothing happens.
Send another notification. Nothing happen.
Send a gmail to the device. It wakes up, show the two notification and gmail notification also.

Just for these tests, I'm using the B4J tool to send notification ( a bit adapted to my needings but the core should be the same)

Any ideas ?
 

marcick

Well-Known Member
Licensed User
Longtime User
But how all other apps do ? WhatsApp, mail, etc
How can be useful a notification if it does not notify you an event ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
So we can stop tu use Firebase notifications because they will not work when you need they work ?
I'm confused. Possible there isn't any solution ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Sorry Erel: I have a very popular Samsung S8 with Android 9 and it does not work.
What should I do to implement it correctly ?
Do you mean that if it does not work it's sure there is an error in my code ? (i would hope so)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have a very popular Samsung S8 with Android 9 and it does not work.
I have a Samsung Note 8 with Android 9 and it does work.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Do you live it a copule of minutes in sleep and it is able to receive firebase notification ?
Would be a good news.
I'll put togheter a sample app and see.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ok guys, I've put togheter the B4J sample app to send notification and the B4A sample App too.
Find them attached.
To run all you need to

1) declare proper apikey in the B4A app
2) set the correct package name of B4A app and register in the firebase console.
3) download the proper google-services.json file an put in the B4A app folder.

Testing on a Samsung S8 Android 9

As soon as you put the device in sleep, you can receive notifications, but if you wait a couple of minutes not (they are "buffered". You will receive them when the device wakes up for other reasons)

I do hope I'm doing something of wrong.
 

Attachments

  • AndroidApp.zip
    9.4 KB · Views: 201
  • B4JApp.zip
    2.7 KB · Views: 162
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Looks like the problem is described here, but I have no deep knowledge to understand what to do
This is not related as the B4J code always sends data messages.

I don't think that you are doing anything wrong. You will see that the messages do eventually arrive. Try to click on the notification whenever it comes. Newer versions of Android are more sophisticated and can apply all kinds of heuristics to decide when to wake up the device.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thanks Erel but .... I must find a solution.
In my case also a 1 minute delay in notification cause big troubles.
And there is no chances to convince my customers with any arguments because other apps does not have this problem.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Thanks Erel but .... I must find a solution.
In my case also a 1 minute delay in notification cause big troubles.
And there is no chances to convince my customers with any arguments because other apps does not have this problem.
FWIW - I find that my Pixel (running Pie) has similar issues. I haven't really kept track of the details, but it seems that some notifications don't show up until I wake the phone up, but others do.

I just put it down to yet another restriction in Pie due to Android's ever increasing desire to improve battery life.

- Colin.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
There was a time ... my app was structured with background services that had cyclic connections with my server (every 15 sec) to sync data and give instant local notifications when an event occoured.
Then had become more difficult to maintain background services running and not be killed by OS, so I moved to remote notification structure.
That had worked great. Just for a while ....
I can't understand. There must be a solution to have a realtime alarm when an event occour at server side.
I have the same app for IOS also and notifications work perfect. And who is more severe than Apple in put limitations to developers ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I'm reading a lot on internet, search for "Android notification delay" and you will see tons of threads of people struggling for this issue.
Yes, the problem is related to battery optimiziation and DOZE mode, introduced in the lasts Android versions.
You fill find a lot of hints on how to disable this feature but (in my case) they don't work. This is a good place where everything is well summarized, if you want to give it a try.

Definitely, you must disable DOZE mode if you want instant notifications as before, but the only method that seems to work is through ADB (and need to be repeated everytime you restart the device). If you want to try, follow here (you can revert back without problems then). I've just tried and it works perfect, but I can't say if it has an impact on battery life (I suppose yes).
There is also a 5$ app on PlayStore to easily disable DOZE mode, I didn't try it yet.

I'm disappointed: if you navigate in settings menù there are all the options to disable doze (also for specific apps only), to allow data in background etc. But they simply has no effect. How is it possible ? I understand the goal for a manufacturer is to maximize battery life, but why don' give the user the option to choose what to do ?
In our days (and in my opinion) instant notifications are mandatory. What fucking notification is if you are informed of a motion detection, an alarm, a simple message also, after 5 minutes ?
 
Upvote 0
Top