Android Question FirebaseMessaging service stop running - how to do for obtain an 'unbreakable service' ?

amorosik

Expert
Licensed User
I wrote an app, following Erel's basic Fcm example, with foreground screenshots, which contains the FirebaseMessaging service for receiving push notifications
Being the code enclosed within a service, I thought that the notification reception should always remain active
On the other hand, if I press the 'recent app' button and then the icon in the center of the app, 'application information' and then 'forced shutdown' my app switches off
And with it the possibility of sending push notifications to the phone
Question is: how to write an app that contains a service 'unbreakable' for receiving push notifications?
 

Star-Dust

Expert
Licensed User
Longtime User
Yes, this is what i searching for
How to realize a "..floating app that the system doesn't kill.." ?
Try Mashaine's cobweb. Is a good suggestion

For the floating App look for STANDOUT
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Most of the information in this thread is wrong.

Assuming that you followed the tutorial correctly and are using the B4J code to send the messages, notifications will arrive even when the service is not running.
It is true that on some devices, explicitly killing the app will prevent it, but on most devices it will work properly.
 
Upvote 0

amorosik

Expert
Licensed User
Most of the information in this thread is wrong.

Assuming that you followed the tutorial correctly and are using the B4J code to send the messages, notifications will arrive even when the service is not running.
It is true that on some devices, explicitly killing the app will prevent it, but on most devices it will work properly.

Well, I'm starting from the original Fcm example published in 2019, which I will call app X
I am using the attached B4J program to send notifications
I verified that if the X app is turned off by the operator, then the notifications are no longer received, at least on a Samsung A10 phone with Android ver 10
I have 30 identical phones on which to activate a system that allows me to start my main app from a command sent from a pc
I thought fcm notifications were the safest system, because the only one that allows you to communicate even with the phone at rest and display off Unfortunately this is not the case, At least on the Samsung A10, because if the operator turns off the X app that receives commands via fcm, from that moment on I can no longer send commands to the phone when it is at rest and the display is off.
The question is: how to ensure that the X app keeps working even after an attempted shutdown by the operator?
Is it possible to intercept the closing request, whether it comes from manual operation or from the operating system, to start X2 app (which will do the same things as X)?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
As this thread is full of misleading information, we need to be very accurate. Posts not by @amorosik or myself will be deleted.
Push notifications are indeed the only reliable way to send notifications.

I verified that if the X app is turned off by the operator
I don't know what it means.

Start with this test:
- Create a new project and carefully follow the instructions: https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/
- Run your app in release mode.
- Click on the home button.
- Send a push notification with the B4J project.
A. Do you see the notification?

- Reboot the device and wait a minute or two until the device is ready.
- Send another message with the B4J project.
B. Do you see the notification?

Don't do anything not listed above.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Then?
Have you read my request?
My request is "..how to write an unbreakable system for receive..."
Please don't be rude. I'm trying to help you. I can stop if you prefer.

A- yes
B- yes
B - yes = This is important test. It means that notifications were implemented properly and your app is receiving notifications, even when it is not running (I assume that you followed the instructions and have NOT set #StartAtBoot: true).

This is the best you can do. The upside is that it will work on 99% of the cases. This is quite good.
On the other hand, if I press the 'recent app' button and then the icon in the center of the app, 'application information' and then 'forced shutdown' my app switches off
This is a non-solvable, non-issue. No user will close your app like this. Anyway, there is nothing that you can do about it as the app enters the STOPPED mode and will never start again until the user explicitly starts it. This is not the same as killing the app with a swipe (which can also cause your app to enter the STOPPED mode on some misbehaving devices).
 
Upvote 0

amorosik

Expert
Licensed User
Please don't be rude. I'm trying to help you. I can stop if you prefer.


B - yes = This is important test. It means that notifications were implemented properly and your app is receiving notifications, even when it is not running (I assume that you followed the instructions and have NOT set #StartAtBoot: true).

This is the best you can do. The upside is that it will work on 99% of the cases. This is quite good.

This is a non-solvable, non-issue. No user will close your app like this. Anyway, there is nothing that you can do about it as the app enters the STOPPED mode and will never start again until the user explicitly starts it. This is not the same as killing the app with a swipe (which can also cause your app to enter the STOPPED mode on some misbehaving devices).

Sorry, I didn't mean to be rude
And I assure you that your help, even if we often forget to remember it, is priceless

It is not true that "..no user will close your app like this .."
If there is a way to stop working, rest assured they will find it
And for this I am trying to find a system for which it is not possible to interrupt the communication system via fcm
And if that happens, there has to be a system that quickly restores it
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not true that "..no user will close your app like this .."
If there is a way to stop working, rest assured they will find it
And for this I am trying to find a system for which it is not possible to interrupt the communication system via fcm
And if that happens, there has to be a system that quickly restores it
I've already answered this non-solvable non-real-issue:

"Anyway, there is nothing that you can do about it as the app enters the STOPPED mode and will never start again until the user explicitly starts it. This is not the same as killing the app with a swipe (which can also cause your app to enter the STOPPED mode on some misbehaving devices)."
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am currently developing a security application, but with this limitation, I will have to stop the project, the client cannot be asked to check if his application is running, I also have a taxi application, and in this case the client is forced to driver have the application in the foreground all the time, previously the driver had the app in the background and when a service arrived it was activated and ready.
It is quite unbelievable that you are writing it. Read my posts again.

The app doesn't need to run in order to receive push notifications.
The issue discussed here, is that the OP killed the app using Force Close options from the device settings.
 
Last edited:
Upvote 0
Top