@Override public void onLoadChildren( @NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) { if (!mMusicProvider.isInitialized()) { // Use result.detach to allow calling result.sendResult from another thread: result.detach(); mMusicProvider.retrieveMediaAsync( new MusicProvider.Callback() { @Override public void onMusicCatalogReady(boolean success) { if (success) { loadChildrenImpl(parentMediaId, result); } else { updatePlaybackState(getString(R.string.error_no_metadata)); result.sendResult(Collections.<MediaItem>emptyList()); } } }); } else { // If our music catalog is already loaded/cached, load them into result immediately loadChildrenImpl(parentMediaId, result); } }