onLoadChildren 必须调用 detach(),MusicBrowserService,Android?

onLoadChildren must call detach(), MusicBrowserService, Android?

我正在使用 MediaBrowserService 在设备上播放音频。 当我打开蓝牙并播放音频时,应用程序崩溃了。

下面是日志

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.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)

如何处理?

似乎 MediaBrowserService 在错误状态下处理它,请在此处检查生命周期:https://developer.android.com/guide/topics/media-apps/audio-app/building-a-mediabrowserservice#service-lifecycle

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.

https://developer.android.com/reference/android/service/media/MediaBrowserService.html#onLoadChildren(java.lang.String,%20android.service.media.MediaBrowserService.Result%3Cjava.util.List%3Candroid.media.browse.MediaBrowser.MediaItem%3E%3E,%20android.os.Bundle)

必须在 onLoadChildren() 实现中调用某种方式 result.sendResult()