Android Question Is it OK to do .StartForeground in Starter service when I want a Notification to always be shown?

JohnC

Expert
Licensed User
Longtime User
My app is sort of a timer app that needs to continuously display a countdown clock as an always-displayed notification.

So, is it ok to do the below in the "Starter" service for this particular app purpose?
B4X:
Service.StartForeground(MyApp.nid, MyApp.CreateNotification("MyApp","Timer: xx:xx:xx"))
 

DonManfred

Expert
Licensed User
Longtime User
So, is it ok to do the below in the "Starter" service for this particular app purpose?
No

Android 8+ considerations
  • Starting from Android 8, the OS kills services while the app is in the foreground.
  • If you are using B4A v8.30+ then the starter service will not be killed until the whole process is killed.
  • You will see a message such as this one, 60 seconds after the app has moved to the background:
    ** Service (starter) Destroy (ignored)**
  • The above message means that the actual service is destroyed but the starter service is still available.
  • Don't make the starter service a foreground service. It will not work once the backed service is destroyed.
  • If you want to do a background task then you should add another service.
  • Related tutorial: Automatic Foreground Mode
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
What exactly does 'It will not work once the backed service is destroyed" mean?

What is a "Backed Service"?

The reason why I asked this question is that I was having trouble keeping my app running every minute by using a separate service and StartServiceAt(). On an Oreo 8.1 device, the app would just stop during the night.

But when I use the Starter service as the only service, the app kept running all night long.
 
Upvote 0
Top