googlecast / CastVideos-android

Reference Android Sender w/ Framework API: CastVideos-android application shows how to cast videos from an Android device that is fully compliant with the Cast Design Checklist.
Apache License 2.0
345 stars 183 forks source link

android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() #88

Open Discovery-Prachi opened 4 years ago

Discovery-Prachi commented 4 years ago

We are getting following crash sometimes while casting videos and switching to new videos quickly. When we start casting new video we are calling remoteMediaClient?.stop() and then load the new one.

Could you please guide us what can be done to avoid this crash:

cast SDK version used: com.google.android.gms:play-services-cast-framework:18.0.0

android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{c3019d0 u0 com.discovery.plus.uat/com.google.android.gms.cast.framework.media.MediaNotificationService} at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1945) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Discovery-JSwapnil commented 4 years ago

We are getting following crash sometimes while casting videos and switching to new videos quickly. When we start casting new video we are calling remoteMediaClient?.stop() and then load the new one.

Could you please guide us what can be done to avoid this crash:

cast SDK version used: com.google.android.gms:play-services-cast-framework:18.0.0

android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{c3019d0 u0 com.discovery.plus.uat/com.google.android.gms.cast.framework.media.MediaNotificationService} at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1945) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Any updates on this?

chinmaygghag commented 4 years ago

Any updates on this? @Discovery-JSwapnil and @pnkshir did you get to fix this ? If yes, can you give some thoughts of how can this be fixed?

Ethan1983 commented 4 years ago

@anjaneesh We ran into this exception once in a while where the cast session fails because of business logic related errors (location constraints etc).

It seems like Sender SDK invokes startForegroundService but the immediate failure results in stopService even before the service could invoke startForeground. Ideally, Android Framework should not fail such cases. Could this be handled in the Sender SDK to fail gracefully where stopService is delayed until service invokes startForeground?

All occurrences were in Android 9.