question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash when starting services in background

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:35
  • Comments:29 (21 by maintainers)

github_iconTop GitHub Comments

9reactions
SUPERCILEXcommented, Sep 19, 2017

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.

4reactions
veonuacommented, Jun 5, 2018

there is pull a request since December, could you please just merge it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Background Service is crashing on "start service"
The code working fine and it's displaying correct locations but when I click "Start Service" It crashes. I can't find the mistake: GPS ......
Read more >
Screen goes black all background apps crash then screen ...
1. Open the run box by pressing the Windows Key + R and type msconfig · 2. System Configuration Utility box will open...
Read more >
The reasons for the crash of the process in the background.
Many devices don't allow apps to run in the background for too long. Even with a foreground service. Keep the MyLocation app running...
Read more >
CrashPlan app does not run (CrashPlan for Small Business)
CrashPlan app does not run (CrashPlan for Small Business) ... Opens, but displays the message: Cannot connect to background service.
Read more >
Solved: Windows 10 Crashes on Startup
Part 2. How to Fix Windows 10 Crashed on Startup? · Method 1. Cleaning Dust · Method 2. Stop Fast Startup · Method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found