0

I have been researching without results for some time now. A foreground service whose service is forever running needs to be created. Idea can be found on this gist: https://gist.github.com/varunon9/f2beec0a743c96708eb0ef971a9ff9cd

Issues is that when starting a foreground service from a Worker or from onDestroy() lifecycle callback of the ForegroundService itself the following error would appear:

android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.example.myapp/com.example.myapp.proxy.service.MyForegroundService

Does someone have an idea on how to implement this properly?

4
  • 2
    A forever service has never been completely possible in android and now there are even more restrictions where you cannot start a service while your app is in the background. Please see the documentation developer.android.com/develop/background-work/services/… Commented Oct 16, 2024 at 13:37
  • I read the documentation before posting this question, am looking to see if someone has found a way to do this Commented Oct 17, 2024 at 7:55
  • 1
    its not possible like I said, the OS can always kill your service if it needs to without notification Commented Oct 17, 2024 at 12:16
  • No no, assume service is with a notification. Performing a longer running task after that @tyczj Commented Oct 18, 2024 at 10:57

1 Answer 1

0

This isn't necessary authoritative.

This is a feature, not a bug. Services must be capable of being terminated due to the Cybersecurity requirements of a Trusted Computing Base. Otherwise, it looks very similar to malware or antivirus software.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Robert, I know that. Thing is sometimes there is a task that needs to be finished at some point later in time. Like finishing some transaction and similar even if the user/OS kills the app. How can that be managed? Foreground service is with the notification but still doesn't run

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.