Android Question App crashes: Android 8.0 Background execution limits

Discussion in 'Android Questions' started by Multiverse app, Jan 5, 2018.

  1. Multiverse app

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

    Screenshot_20180105-152341.jpg

    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
     

    Attached Files:

    Last edited: Jan 5, 2018
  2. Multiverse app

    Multiverse app Active Member Licensed 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?
     
  3. DonManfred

    DonManfred Expert Licensed User

    at least it will be harder and harder with every new android version, yes.
    It may be the solution. Maybe.

    But it seems that the B4A Compiler needs an Update for it. Erel said he´ll adress it but it may take some time.
    Check this thread: https://www.b4x.com/android/forum/threads/android-job-scheduler.87630/
     
    Peter Simpson and Multiverse app like this.
  4. Multiverse app

    Multiverse app Active Member Licensed User

    Does it mean Android will kill services started Service.StartForeground with too?
     
  5. DonManfred

    DonManfred Expert Licensed User

    Check the Google documentation... StartForeground seems to be a bad practice for android and Google will fight against.
     
    Multiverse app likes this.
  6. Multiverse app

    Multiverse app Active Member Licensed User

     
  7. Erel

    Erel Administrator Staff Member Licensed 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.
    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).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice