leakcanary: Crash when starting services in background
Using a Pixel on Oreo (release not beta), I put my app in the background. A minute or two later, it crashed. LeakCanary 1.5.1
09-07 19:18:24.049 31787-31804/com.myapp:leakcanary E/AndroidRuntime: FATAL EXCEPTION: IntentService[HeapAnalyzerService]
Process: com.myapp:leakcanary, PID: 31787
java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.myapp/com.squareup.leakcanary.DisplayLeakService (has extras) }: app is in background uid UidRecord{74385af u0a385 CEM bg:+3m4s764ms 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 com.squareup.leakcanary.AbstractAnalysisResultService.sendResultToListener(AbstractAnalysisResultService.java:38)
at com.squareup.leakcanary.internal.HeapAnalyzerService.onHandleIntent(HeapAnalyzerService.java:59)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:68)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 33
- Comments: 29 (18 by maintainers)
Commits related to this issue
- Allow starting the service from the background This should help with #846 — committed to square/leakcanary by pyricau 8 years ago
- Allow starting the service from the background This should help with #846 — committed to square/leakcanary by pyricau 8 years ago
- https://github.com/square/leakcanary/issues/846 — committed to iceCola7/WanAndroid by iceCola7 8 years ago
Yeah, that’s because you can’t start services in the background anymore on API 26.
@JakeWharton @jrodbx You’ll have to use
ContextCompat.startForegroundService(...)and post a notification while processing the leak. I think that’s actually better UX anyway because I’m always like “Is LeakCanary doing anything? Why is it taking so long?” If you guys could have a progress bar showing the analysis progress, that would be really cool.there is pull a request since December, could you please just merge it.
@SUPERCILEX @eygraber I just merged that fix to master, a new snapshot should be automatically published soon, please let us know if that fixes it.
I’m looking at it right now.
Everyone’s already doing it, so we might as well jump off the bridge too.
On Mon, Dec 18, 2017 at 10:17 AM shmuelr notifications@github.com wrote: