I have been using Mapbox version 4.2.2 as I am not yet prepared to move to Mapbox 5 as a few features from version 4 don't seem to be supported. (In specific Camera Tracking)
I have found that I am getting crashes regarding Android 8 devices.
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.sctaylor.map/com.mapbox.mapboxsdk.telemetry.TelemetryService }: app is in background uid UidRecord{3534d78 u0a235 CEM idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1512)
at android.app.ContextImpl.startService(ContextImpl.java:1468)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at com.mapbox.mapboxsdk.telemetry.MapboxEventManager.setTelemetryEnabled(MapboxEventManager.java:252)
at com.mapbox.mapboxsdk.telemetry.MapboxEventManager.initialize(MapboxEventManager.java:146)
at com.mapbox.mapboxsdk.MapboxAccountManager.start(MapboxAccountManager.java:50)
at com.sctaylor.map.AnalyticsApplication.onCreate(AnalyticsApplication.java:44)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5821)
at android.app.ActivityThread.-wrap1(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6580)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
It looks like this is an issue with Android 8's background service restrictions (Need to use a job scheduler). Is there a way to fix this without upgrading to Mapbox 5?
It looks like this is an issue with Android 8's background service restrictions (Need to use a job scheduler). Is there a way to fix this without upgrading to Mapbox 5?
You are completely right about the cause of the issue.
The issue was reported here on GitHub, updates will be propagated here.
The clean fix is for Mapbox to implement JobScheduler. However, they have not released the fix yet and I don't know if they will fix it for versions 4.x
As a contemporary fix, they just caught the IllegalStateException
while Mapbox still seems to work.
Using the try/catch approach around MapboxAccountManager.start()
does not seem to be a good idea because code subsequent to setTelemetryEnabled()
would not be executed.
The only workaround I see is degrading the targetSdkVersion to 25.