I'm investigating several IllegalStateExceptions only on Android 9 devices which I cannot reproduce. First I thought it depends on the restriction starting services in background, but 1st they were introduced in Android 8 and I dont get these exceptions on Android 8 and 2nd the stacktrace shows the service was started from onCreate, so it was in foreground, isnt it?
The full stacktrace:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3430)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3614)
at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2199)
at android.os.Handler.dispatchMessage (Handler.java:112)
at android.os.Looper.loop (Looper.java:216)
at android.app.ActivityThread.main (ActivityThread.java:7625)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
caused by java.lang.IllegalStateException:
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1810)
at android.app.ContextImpl.startService (ContextImpl.java:1765)
at android.content.ContextWrapper.startService (ContextWrapper.java:664)
at com.max.power.ServiceManager.doStartService (ServiceManager.java:121)
at com.max.power.ServiceManager.start (ServiceManager.java:82)
at com.max.power.ActivityLogin.setupSocketService (ActivityLogin.java:259)
at com.max.power.ActivityLogin.onCreate (ActivityLogin.java:156)
at android.app.Activity.performCreate (Activity.java:7458)
at android.app.Activity.performCreate (Activity.java:7448)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1286)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3409)
The line doStartService (ServiceManager.java:121) is:
mActivity.startService(new Intent(mActivity, mServiceClass));
Can anyone imagine whats going on there?
Any help would be much appreciated. Thank you!