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?
 

DonManfred

Expert
Licensed User
Longtime User
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 expected. Forcing the app to shutdown is like the app crashes unexpected.

Start the app manually again and it should work again.
 
Upvote 1

Star-Dust

Expert
Licensed User
Longtime User
I see that you are not interested in answering the question
Patience, I hope some other expert can provide the information I am looking for, or explain why this request is not feasible in some way
Forgive me, but I think you don't understand the answer.
There is no remedy for forcibly closing the App.

While in the past the services could remain with specific types such as sticky services, and more. Over time, with the new versions, the services are still closed by the operating system to save energy and in any case are turned off if you kill the App

Even if you create a service that verifies that the App is running, the frequency cannot be more than half an hour.

I see few alternatives in this. For example, open two activities, one that is floating and that does not appear on the task manager so that it is not killed by the o.s. From the task manager and an activity that acts as a Layout for the user.
 
Upvote 1

FrostCodes

Active Member
Licensed User
Longtime 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?
Unfortunately, I don't think there is would be any solution to this as I asked a similar question: https://www.b4x.com/android/forum/threads/a-little-confused-about-push-notifications.133805


I advise you to read this: https://www.b4x.com/android/forum/t...d-about-push-notifications.133805/post-847410
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
He is not force killing the app... what he is trying to say is that he cleared his recent app list in his launcher.

Unfortunately, I don't think there is would be any solution to this as I asked this same question: https://www.b4x.com/android/forum/threads/a-little-confused-about-push-notifications.133805


I advise you to read this: https://www.b4x.com/android/forum/t...d-about-push-notifications.133805/post-847410
cleared his recent app list in his launcher = force killing the app :p

A different way to express the same concept
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
cleared his recent app list in his launcher = force killing the app :p

A different way to express the same concept
Accordingly to android documentation it's not the same... In fact, I see no reason why an app should remain in my recent app list, it uses battery. The whole aim of FCM(push) is I can still communicate with my users in the background and rengage them.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Accordingly to android documentation it's not the same... In fact, I see no reason why an app should remain in my recent app list, it uses battery. The whole aim of FCM(push) is I can still communicate with my users in the background and rengage them.
It won't be the same but it has the same effect.

In any case, you must bind the service or the App so that it cannot be suspended. With the latest releases it is a more difficult thing to achieve.
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
It won't be the same but it has the same effect.

In any case, you must bind the service or the App so that it cannot be suspended. With the latest releases it is a more difficult thing to achieve.
Happy you are now understanding his question... He is asking how to do the binding... The Firebase Instance is getting suspended that's why he is asking how to keep it alive so it doesn't get suspended.

The whole goal of using Fcm is not for foreground notifications because if it was that, why can't the developer roll his own solution and avoid google (as a lot of devs don't like them) ... The end goal is background notifications and FCM is failing in this case meaning it's not useful to most people anymore.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Happy you are now understanding his question... He is asking how to do the binding... The Firebase Instance is getting suspended that's why he is asking how to keep it alive so it doesn't get suspended.

The whole goal of using Fcm is not for foreground notifications because if it was that, why can't the developer roll his own solution and avoid google (as a lot of devs don't like them) ... The end goal is background notifications and FCM is failing in this case meaning it's not useful to most people anymore.
I had asked the question even before. In fact, the answer is the same.

In order to keep the service you can now do so by keeping the App in the foreground or floating.

There would be other more complicated systems but I would leave it alone and I don't remember how they are implemented anymore and therefore I would not know how to explain them
 
Upvote 0

amorosik

Expert
Licensed User
Forgive me, but I think you don't understand the answer.
There is no remedy for forcibly closing the App.

While in the past the services could remain with specific types such as sticky services, and more. Over time, with the new versions, the services are still closed by the operating system to save energy and in any case are turned off if you kill the App

Even if you create a service that verifies that the App is running, the frequency cannot be more than half an hour.

I see few alternatives in this. For example, open two activities, one that is floating and that does not appear on the task manager so that it is not killed by the o.s. From the task manager and an activity that acts as a Layout for the user.

It may be that I don't understand the answer given
Maybe because there was no response to the request
What if, when the main app is closed, a second program is started whose only purpose is to restart the main app after a few seconds?
Is it possible to intercept an app closing event?
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
If your users don't mind a permanent notification that [My App is running]....

add this to Service Start sub of the firebase service

B4X:
    Service.StartForeground(nid, CreateNotification("My App is running"))
    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)


B4X:
Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icon"
    notification.SetInfo("MyApp", Body, Main)
    Return notification
End Sub

in process globals...

B4X:
Private nid As Int = 1

This re-starts and never terminates the FB service. You can search the forum on StartServiceAt usage, this was my trial, so far no issues.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
It may be that I don't understand the answer given
Maybe because there was no response to the request
What if, when the main app is closed, a second program is started whose only purpose is to restart the main app after a few seconds?
Unfortunately it is the verification that google does for the consumption of the battery.
A second App is not required, even a service can verify that the App is active.

The service must restart every few seconds. But this service would be killed by the system.

That's why I suggested a floating app that the system doesn't kill.

In any case, see on the forum if there are other ways to keep a service running in the background, that would perhaps solve the problem for you
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
I had asked the question even before. In fact, the answer is the same.

In order to keep the service you can now do so by keeping the App in the foreground or floating.

There would be other more complicated systems but I would leave it alone and I don't remember how they are implemented anymore and therefore I would not know how to explain them
Using foreground mode is bad for push notification because imagine you turn on your phone and you saw a notification like Facebook is checking for push notifications all day long and all your app also has something like that.. that's just bad design. How would you feel?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If your users don't mind a permanent notification that [My App is running]....

add this to Service Start sub of the firebase service

B4X:
    Service.StartForeground(nid, CreateNotification("My App is running"))
    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)


B4X:
Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icon"
    notification.SetInfo("MyApp", Body, Main)
    Return notification
End Sub

in process globals...

B4X:
Private nid As Int = 1

This re-starts and never terminates the FB service. You can search the forum on StartServiceAt usage, this was my trial, so far no issues.
It is a good suggestion to put a notification icon. I usually use it for widgets which are services that usually don't get killed
 
Upvote 0

amorosik

Expert
Licensed User
Unfortunately it is the verification that google does for the consumption of the battery.
A second App is not required, even a service can verify that the App is active.

The service must restart every few seconds. But this service would be killed by the system.

That's why I suggested a floating app that the system doesn't kill.

In any case, see on the forum if there are other ways to keep a service running in the background, that would perhaps solve the problem for you

Yes, this is what i searching for
How to realize a "..floating app that the system doesn't kill.." ?
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
It may be that I don't understand the answer given
Maybe because there was no response to the request
What if, when the main app is closed, a second program is started whose only purpose is to restart the main app after a few seconds?
Is it possible to intercept an app closing event?
Android would eventually kill your app fully after let's say 30 minutes... I tried doing this and if android notices your app is doing this restart too much it would blacklist/limit your app from restarting and restarting
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Using foreground mode is bad for push notification because imagine you turn on your phone and you saw a notification like Facebook is checking for push notifications all day long and all your app also has something like that.. that's just bad design. How would you feel?
I do not use facebook, however I understand that it is not nice, I have not imposed certain limits. You don't have to convince me

Before, many more things could have been done more easily, now it is more complicated. If you can try to convince mr google.
 
Upvote 0
Top