I am using MediaBrowserServiceCompat
to support Android Auto
.
From the crash reports (I added one of them at the bottom of this question) I see that there is a problem in onLoadChildren
method that I override.
I do this:
if(parentId == null){
result.sendResult(null);
return;
}
Because in the documentation it says if the parentId
is invalid, call sendResult
with null
. It is crashing but instead of crashing it should do this according to the documentation:
"When the given parentId is invalid, implementations must call result.sendResult with null, which will invoke MediaBrowserCompat.SubscriptionCallback.onError."
On the other hand, the documentation also mentions the following for parentId
:
parentId
: String: The id of the parent media item whose children are to be queried. This value must never be null.
So, here comes my questions:
1) How (and why) does parentId
get set to null
while the documentations says that it must not be null
. I cannot control this as the system calls onLoadChildren
with null parentId
.
2) Why does it crash instead of invoking MediaBrowserCompat.SubscriptionCallback.onError.
as the documentation states?
One of those crash reports:
Fatal Exception: java.lang.IllegalStateException: onLoadChildren sent null list for id null
at android.service.media.MediaBrowserService$3.onResultSent + 473(MediaBrowserService.java:473)
at android.service.media.MediaBrowserService$3.onResultSent + 469(MediaBrowserService.java:469)
at android.service.media.MediaBrowserService$Result.sendResult + 131(MediaBrowserService.java:131)
at androidx.media.MediaBrowserServiceCompat$ResultWrapper.sendResult + 1274(MediaBrowserServiceCompat.java:1274)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$2.onResultSent + 416(MediaBrowserServiceCompat.java:416)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$2.onResultSent + 404(MediaBrowserServiceCompat.java:404)
at androidx.media.MediaBrowserServiceCompat$Result.sendResult + 857(MediaBrowserServiceCompat.java:857)
at com.myapp.myMediaBrowserService.onLoadChildren + 124(myMediaBrowserService.java:124)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21.onLoadChildren + 425(MediaBrowserServiceCompat.java:425)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$MediaBrowserServiceApi21.onLoadChildren + 515(MediaBrowserServiceCompat.java:515)
at android.service.media.MediaBrowserService.performLoadChildren + 495(MediaBrowserService.java:495)
at android.service.media.MediaBrowserService.addSubscription + 459(MediaBrowserService.java:459)
at android.service.media.MediaBrowserService.access$400 + 68(MediaBrowserService.java:68)
at android.service.media.MediaBrowserService$ServiceBinder$3.run + 247(MediaBrowserService.java:247)
at android.os.Handler.handleCallback + 739(Handler.java:739)
at android.os.Handler.dispatchMessage + 95(Handler.java:95)
at android.os.Looper.loop + 148(Looper.java:148)
at android.app.ActivityThread.main + 7331(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1230(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main + 1120(ZygoteInit.java:1120)