Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Android 8.0 and later (IllegalStateException: Not allowed to start service) #630

Closed
DonTomika opened this issue Jan 31, 2018 · 0 comments

Comments

@DonTomika
Copy link

DonTomika commented Jan 31, 2018

ACRA might prevent the app from starting up on Android 8.0 and later in certain cases.

Versions tested: 5.0.2, 5.0.1, 4.10.0

Steps to reproduce:

  1. Build an app using targetSdkVersion >= 26.
  2. Qneue an error report (let the app crash or use handleException) and make sure the app is not running.
  3. Invoke one of the app's services/receivers from the background (e.g. by sending a push notification).
  4. The app will crash on startup.

Stack trace:

01-31 08:46:58.278 27051-27051/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.example.test, PID: 27051
                                                   java.lang.RuntimeException: Unable to instantiate application com.example.test.App: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.test/org.acra.sender.SenderService (has extras) }: app is in background uid UidRecord{1d6827c u0a331 RCVR bg:+1m15s763ms idle procs:2 seq(0,0,0)}
                                                       at android.app.LoadedApk.makeApplication(LoadedApk.java:984)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6103)
                                                       at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1715)
                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                       at android.os.Looper.loop(Looper.java:180)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6944)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:835)
                                                    Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.test/org.acra.sender.SenderService (has extras) }: app is in background uid UidRecord{1d6827c u0a331 RCVR bg:+1m15s763ms idle procs:2 seq(0,0,0)}
                                                       at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505)
                                                       at android.app.ContextImpl.startService(ContextImpl.java:1461)
                                                       at android.content.ContextWrapper.startService(ContextWrapper.java:644)
                                                       at org.acra.sender.SenderServiceStarter.startService(SenderServiceStarter.java:53)
                                                       at org.acra.util.ApplicationStartupProcessor.sendApprovedReports(ApplicationStartupProcessor.java:110)
                                                       at org.acra.util.ApplicationStartupProcessor.checkReports(ApplicationStartupProcessor.java:60)
                                                       at org.acra.ACRA.init(ACRA.java:234)
                                                       at org.acra.ACRA.init(ACRA.java:160)
                                                       at org.acra.ACRA.init(ACRA.java:144)
                                                       at com.example.test.App.attachBaseContext(App.java:69)
                                                       at android.app.Application.attach(Application.java:198)
                                                       at android.app.Instrumentation.newApplication(Instrumentation.java:1110)
                                                       at android.app.Instrumentation.newApplication(Instrumentation.java:1094)
                                                       at android.app.LoadedApk.makeApplication(LoadedApk.java:969)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6103) 
                                                       at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1715) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                       at android.os.Looper.loop(Looper.java:180) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:6944) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:835) 

Cause: Starting from Android 8.0, startService will throw an IllegalStateException if the app is not in the foreground. This can be solved in multiple ways, one of them is migrating SenderService from IntentService to JobIntentService.

Note: passing checkReportsOnApplicationStart = false to ACRA.init also prevents the crash, but then the app itself will be responsible for sending queued reports in appropriate places. This might be difficult and also won't work well for widget-only apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant