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:
- Created 4 years ago
- Reactions:4
- Comments:22 (9 by maintainers)
I guess I’ll try and remove it from our ExpoKit project then, as we don’t use it.
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.