In the last ~24 hours, we've seen a few thousand crashes within Google's MediaNotificationService
:
Fatal Exception: android.app.RemoteServiceException
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{f9a4deb u0 <our package name>/com.google.android.gms.cast.framework.media.MediaNotificationService}
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1855)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:6986)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445)
I've experienced similar issues when creating my own foreground service, but as this is within the cast library we have no control over it.
The Chromecast receiver is handled by a third party. We are using:
api "com.google.android.gms:play-services-cast:17.0.0"
api "com.google.android.gms:play-services-cast-framework:17.0.0"
Potential clues:
- It is happening on OnePlus, Huawei, Samsung, Google, seemingly every manufacturer (and OS level) in numbers correlating to their market share.
- The crashes are occurring on different lines for different devices (e.g. the above is the Galaxy S9, the S8 crashes on line 1872 instead), so are not grouped together on Crashlytics. This suggests to me it's an OS / Google Play Services level issue.
- The crashes happen across all active versions of the app, starting at the same time.
- The crashes have been occurring in low numbers for months, but suddenly spiked over the weekend and show no sign of slowing down.
UPDATE: Finally managed to reproduce this. The crash happens when casting content for a long period of time with the screen locked, and then disconnecting from the device. Maybe one step closer to a solution...