Android Question App crashes: Android 8.0 Background execution limits

Multiverse app

Active Member
Licensed User
Longtime 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: https://drive.google.com/file/d/1WtgdWGSY0W_RizmROnJwRNeSDde8Q8dh/view?usp=sharing



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)}

android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4037)
android.app.ActivityThread.-wrap21 ()
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2006)
android.os.Handler.dispatchMessage (Handler.java:108)
android.os.Looper.loop (Looper.java:166)
android.app.ActivityThread.main (ActivityThread.java:7396)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:926)

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.app.ContextImpl.startServiceCommon (ContextImpl.java:1701)
android.app.ContextImpl.startService (ContextImpl.java:1657)
android.content.ContextWrapper.startService (ContextWrapper.java:644)
anywheresoftware.b4a.keywords.Common.StartService (Common.java:882)
anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:95)
com.multiverse.jarvis.ttsservice.onStartCommand (ttsservice.java:68)
android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4009)
android.app.ActivityThread.-wrap21 ()
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2006)
android.os.Handler.dispatchMessage (Handler.java:108)
android.os.Looper.loop (Looper.java:166)
android.app.ActivityThread.main (ActivityThread.java:7396)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:926)



The Google Developer console shows:


java.lang.IllegalStateException
anywheresoftware.b4a.keywords.Common.StartService

java.lang.RuntimeException:

at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4037)
at android.app.ActivityThread.-wrap21 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2006)
at android.os.Handler.dispatchMessage (Handler.java:108)
at android.os.Looper.loop (Looper.java:166)
at android.app.ActivityThread.main (ActivityThread.java:7396)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:926)

Caused by: java.lang.IllegalStateException:

at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1701)
at android.app.ContextImpl.startService (ContextImpl.java:1657)
at android.content.ContextWrapper.startService (ContextWrapper.java:644)
at anywheresoftware.b4a.keywords.Common.StartService (Common.java:882)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:95)
at com.multiverse.jarvis.ttsservice.onStartCommand (ttsservice.java:68)
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4009)


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
 

Attachments

  • Starter.bas
    3.6 KB · Views: 472
  • TTSService.bas
    4.9 KB · Views: 510
  • AndroidManifest.xml
    9.7 KB · Views: 402
Last edited:

Multiverse app

Active Member
Licensed User
Longtime User
From the Error code, I found this answer: https://stackoverflow.com/questions...eexception-not-allowed-to-start-service-inten

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?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Multiverse app

Active Member
Licensed User
Longtime User
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Relevant tutorial: https://www.b4x.com/android/forum/threads/87610/#content

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).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…