Android Question App crashes: Android 8.0 Background execution limits

Multiverse app

Active Member
Licensed User
One of my apps recently started crashing randomly, with no information in logs whatsoever. I have been debugging for 5 days now, and have no idea what is causing the issue. I have tried to debug every module, change targetSdkVersion, and recompile many times.
As the project is very big, I am not able to upload it here (and also for security purposes).

The minSdkVersion of project is 21 and targetSdkVersion is 27

I have uploaded the APK build here:


The crash reports in firebase show:

RuntimeException - ActivityThread.handleServiceArgs

Exception java.lang.RuntimeException: Unable to start service com.multiverse.jarvis.ttsservice@cdc6b0c with null: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.multiverse.jarvis/.starter }: app is in background uid UidRecord{e56f5b9 u0a705 SVC idle procs:1 seq(0,0,0)} ( ()$H.handleMessage (
android.os.Handler.dispatchMessage (
android.os.Looper.loop ( (
java.lang.reflect.Method.invoke ($ ( (

Caused by java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.multiverse.jarvis/.starter }: app is in background uid UidRecord{e56f5b9 u0a705 SVC idle procs:1 seq(0,0,0)} ( (
android.content.ContextWrapper.startService (
anywheresoftware.b4a.keywords.Common.StartService (
anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (
com.multiverse.jarvis.ttsservice.onStartCommand ( ( ()$H.handleMessage (
android.os.Handler.dispatchMessage (
android.os.Looper.loop ( (
java.lang.reflect.Method.invoke ($ ( (

The Google Developer console shows:



at (
at (Unknown Source)
at$H.handleMessage (
at android.os.Handler.dispatchMessage (
at android.os.Looper.loop (
at (
at java.lang.reflect.Method.invoke (Native Method)
at$ (
at (

Caused by: java.lang.IllegalStateException:

at (
at (
at android.content.ContextWrapper.startService (
at anywheresoftware.b4a.keywords.Common.StartService (
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (
at com.multiverse.jarvis.ttsservice.onStartCommand (
at (

I have attached the above-mentioned Starter, TTSservice modules, and AndroidManifest.

It would be grateful if this issue is solved.
Thank you.

Edit: Now I know the reason, just have to find a solution


Last edited:

Multiverse app

Active Member
Licensed User
From the Error code, I found this answer:
The permitted situations are a temporary whitelist where the background service behaves the same as before Android O.

Under certain circumstances, a background app is placed on a temporary whitelist for several minutes. While an app is on the whitelist, it can launch services without limitation, and its background services are permitted to run. An app is placed on the whitelist when it handles a task that's visible to the user, such as:

  • Handling a high-priority Firebase Cloud Messaging (FCM) message.
  • Receiving a broadcast, such as an SMS/MMS message.
  • Executing a PendingIntent from a notification.
  • Starting a VpnService before the VPN app promotes itself to the foreground.

So in other words if your background service does not meet the whitelist requirements you have to use the new JobScheduler. It's basically the same as a background service, but it gets called periodically instead of running in the background continuously.
In short, Apps that are running in the background now have limits on how freely they can access background services. I guess now any app targeting API level 26 or above, using background services will have to use jobscheduler?


Licensed User

Multiverse app

Active Member
Licensed User
Context.startForegroundService() method starts a foreground service. The system allows apps to call Context.startForegroundService() even while the app is in the background. However, the app must call that service's startForeground() method within five seconds after the service is created.


Staff member
Licensed User
Relevant tutorial:

You should set the targetSdkVersion to 25 for now.

You can no longer start services in the background when targetSdkVersion is 26+. This happens internally when you set StartAtBoot to true and in other cases.
StartForeground seems to be a bad practice for android and Google will fight against.
That's not accurate. You are allowed to start foreground services. You are not allowed to start non-foreground services when your app is not in the foreground.
However it requires calling Context.startForegroundService. This must be changed in B4A itself. It will be available soon (soon = probably next month).