Android Question Firebase Push Service and Device Boot

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

Some users reported to me that, after a device boot, my apps those are using FCM service were only restarting to receive push messages after a manual app opening. The information was very strange for me because the push messages from FCM should start the service even with the app and services stopped. Then I tested and confirmed: after a boot,the app must to be restarted manually by user to receive FCM messages again.
I could to put a #StartAtBoot: True in FirebaseMessaging service but , reading the documentation, I really thought that this was unnecessary due the behavior of push protocol?
Does anybody have any experience in this situation?
 

KMatle

Expert
Licensed User
Longtime User
I can confirm that (of course). When I test my apps, I did such a test, too. Sometimes it takes a while 'till the device loads all services after a reboot.

On some phones apps are automatically stopped (due to energy savings). Maybe the users should check that, too.
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
I can confirm that (of course). When I test my apps, I did such a test, too. Sometimes it takes a while 'till the device loads all services after a reboot.

On some phones apps are automatically stopped (due to energy savings). Maybe the users should check that, too.

Especially Huawei phone owners
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Especially Huawei phone owners

Had that on my P8 but on newer Huawei's they changed it (took me hours to find the problem). On my Mate 10 all apps may run in background (on the P8 only known ones like WhatsApp, one had to activate it manually)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Assuming that:
1. You have implemented it correctly.
2. You are using the B4J code to send the message.
3. You haven't explicitly stopped the app.

Then it will work after boot. You don't need to use StartAtBoot.
Hello @Erel ... it's implemented according the tutorial... by the way, as you know, I'm working with FCM since the first version, about 8 years ago, and followed the update for the newer B4X version.
It looks that the assurance of push service starting isn't 100% guaranteed as I noticed that the behavior of the auto start is intrinsically dependent on phone model - ok, could be a bug of Android implementation, but there is a problem. But, in other hand, we could clearly do a workaround if had some way to start the service after the boot (if not started yet).
Using an additional service to call the FCM group registering and "force" the push service starting couldn't be a good security procedure? What do you think?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
You are using the B4J code to send the messages, right?
The messages are being sent by other device using the B4A code - working normally if you open the app after boot, even if the activity is closed/cleaned from recent list. But after boot, if I don't open the app on target device, it doesn't receive the push - the push arrives when the app is opened in target, even if was closed when the message was sent.
After the first time when the app is opened, the behavior is as expected - push arrives doesn't matters if the app is open or not.
Notice that to guarantee that our app will work for newer versions of Android, we are working with Android 8.0 and SDK 26 for all of our projects.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Test it on several devices. If you see it on different types of devices then it is probably an implementation error.
Thanks @Erel . I'll do some tests and post here the results. I did a question in other thread about boot & log that will be very useful to clarify this question. I think that to get the logs when booting will give the answer to the problem.
I'll keep the community updated about the results...
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Can you post the results? I am experiencing a similar problem with devices not receiving the message the next day - am using nodejs to send to topics via REST (basically the same code as from the B4J solution)
Hello @andyr00d ,

After more than 2 years experiencing Firebase Cloud Messages with Android devices I noticed the follow situations:

- Not all the messages will arrive. If the device is off line when the message is sent, it can or not arrive later. There is not a default behavior to define when the messages will be queued and sent later. Sometimes, when the device is on line again, it receives a queue of messages sent in the past... sometimes no.
- In some devices the battery management will avoid the messages to arrive due at least two reasons:
1. The Firebase service in app is put in "sleep" state by Android by the battery management tool OR
2. The network communication of the device is fully or partially turned off (abou the "partial" turn off I could notice that in some specific situations in Samsung devices the internet communication "from" the device is working BUT it's not receiving push notifications)
- There is some special features in Android those are accessible only by the "great developers" - like Facebook, Google and Microsoft. The common developer (like us) is limited to the public resources (unfortunately). The existence of these "special resources" available only for the "big ones" was already discussed some times in this forum and there is no anything to do about this. Apparently with these special methods is possible to build more robust and fail proof apps... :(

My advice for you is this situation for Firebase. Use the FCM to wake up the device and create a message queue that can be called by the app (using a POST method and database) to recover the messages. That's it what's working for me. ;)

Regards!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My advice for you is this situation for Firebase. Use the FCM to wake up the device and create a message queue that can be called by the app (using a POST method and database) to recover the messages. That's it what's working for me.
This is definitely the correct approach, assuming that the messages are important. When your app starts you should check with your server for all messages. The push notification is a trigger.
 
Upvote 0
Top