I am using MediaBrowserService to play audio on the device. When I turn on the bluetooth and play audio the app crashes.
Below is the logs
java.lang.IllegalStateException: onLoadChildren must call detach() or sendResult() before returning for package=com.android.bluetooth id=__ROOT__
at android.service.media.MediaBrowserService.performLoadChildren(MediaBrowserService.java:669)
at android.service.media.MediaBrowserService.addSubscription(MediaBrowserService.java:600)
at android.service.media.MediaBrowserService.-wrap3(MediaBrowserService.java)
at android.service.media.MediaBrowserService$ServiceBinder$3.run(MediaBrowserService.java:272)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
How to handle this?
onLoadChildren()
Called to get information about the children of a media item.
Implementations must call result.sendResult with the list of children. If loading the children will be an expensive operation that should be performed on another thread, result.detach may be called before returning from this function, and then result.sendResult called when the loading is complete.
In case the media item does not have any children, call MediaBrowserService.Result.sendResult(T) with an empty list.
One way or another result.sendResult()
must be called in the onLoadChildren()
implementation.