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.

GcmRegistrationService starting in background is causing a crash and killing the app

See original GitHub issue

🐛 Bug Report

ExpoKit for Android includes a Service called GcmRegistrationService. This service is sometimes getting launched from the background, however since Android 8 you need to use a foreground service (which displays a notification to the user) to do that. Since Expo is trying to start the service from the background, a fatal exception is thrown and the app gets killed!

This is pretty subtle, because this never happens while the user has the app open, only when it is in the background. This has probably slipped under the radar because one might assume the app did not crash but did restart because the phone was running low on memory.

I stumbled upon this issue because it would kill my background location service.

FATAL EXCEPTION: main
Process: foronered.myapp, PID: 31756
java.lang.RuntimeException: Unable to resume activity {foronered.myapp/host.exp.exponent.MainActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=foronered.myapp/host.exp.exponent.gcm.GcmRegistrationIntentService }: app is in background uid UidRecord{461a577 u0a267 TRNB bg:+8m16s20ms idle change:uncached procs:1 proclist:31756, seq(1,1,1)}
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4008)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4040)
	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.j
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(Trans
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7045)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { c
	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1666)
	at android.app.ContextImpl.startService(ContextImpl.java:1611)
	at android.content.ContextWrapper.startService(ContextWrapper.java:677)
	at host.exp.exponent.experience.BaseExperienceActivity.registerForNotifications(
	at host.exp.exponent.experience.ExperienceActivity.onResume(ExperienceActivity.j
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412)
	at android.app.Activity.performResume(Activity.java:7558)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4000)

Environment

ExpoKit v32 Android 9 Samsung Galaxy S8

Steps to Reproduce

Not sure. I am not using Google Cloud Messaging at all, but have logged the exception through adb logcat

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
andersravncommented, Sep 24, 2019

I guess I’ll try and remove it from our ExpoKit project then, as we don’t use it.

1reaction
andersravncommented, Jul 8, 2019

We have a crash rate of 1.32% the last 30 days. The vast majority of those produce the same stack trace as above. They all seem to be happening on Android 9. We are using ExpoKit SDK 30.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash in background on iOS 15 EXC_CRASH (SIGKILL)
Hello, Since the first iOS 15 beta and even with all the next public releases, we have a very weird crash each time...
Read more >
Why do my apps keep crashing on Android, How to fix it
To do this, go to Settings -> Apps and select the app that keeps crashing. Tap on the app's name and then tap...
Read more >
How to Fix Crashing Apps on an iPhone or Android?
Fix App Crashes on your Apple iPhone or Android smartphone. Kill the App; Restart the Phone; Update the App; Official Support; Use Bugfender!...
Read more >
Background services causing crash - android - Stack Overflow
On some devices this seems to work perfectly - The service(s) works in the background, allowing me to use other activities in the...
Read more >
How to Stop Apps From Crashing on Android - AVG
Learn what to do when Android apps keep crashing and how to stop phone ... or figuring out which apps don't need to...
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