When I open activity 1 (Main/Launcher activity of the app), that includes MediaBrowser connection, MediaBrowser.subscribe
works ok (onChildrenLoaded
is being called after it), but when I opened some other activity (number 2) from activity 1 (using button click listener and intent) and then close this activity 2, MediaBrowser.subscribe
stops working - onChildrenLoaded
is NOT being called after subscribing, so after activity 2 finishes onConnected
of SubscriptionCallback (of activity 1) & mMediaBrowser.subscribe(MEDIA_ID_ROOT, mSubscriptionCallback);
are being called but my items aren't updated because onChildrenLoaded
is never triggered
private MediaBrowserCompat.ConnectionCallback mConnectionCallback =
new MediaBrowserCompat.ConnectionCallback() {
@Override
public void onConnected() {
Log.i(TAG, "onConnected");
mMediaBrowser.unsubscribe(MEDIA_ID_ROOT, mSubscriptionCallback);
mMediaBrowser.subscribe(MEDIA_ID_ROOT, mSubscriptionCallback);
}
};
private MediaBrowserCompat.SubscriptionCallback mSubscriptionCallback = new MediaBrowserCompat.SubscriptionCallback() {
@Override
public void onChildrenLoaded(String parentId, List<MediaBrowserCompat.MediaItem> children) {
Log.i(TAG, "onChildrenLoaded"); // isn't being called on android 6.0.1 after I got back to this activity from other
if (children != null) {
if (mMediaItems != null) {
mMediaItems.clear();
mMediaItems = null;
}
mMediaItems = children;
if (mAdapter == null) {
mAdapter = new Adapter();
mRecyclerView.setAdapter(mAdapter);
} else {
mAdapter.notifyDataSetChanged();
}
}
}
@Override
public void onError(String id) {
Log.i(TAG, "SubscriptionCallback onError");
}
};
But it works ok for 4.4.4 Android (no such problems)
Update
It seems like I found this problem on Google Bugs (some Developer reported it): https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=-has%3Asubcomponent%20-has%3Atarget%20emulator%20.&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=232455
But there is no solution
Also have such error:
04-02 18:25:55.519 11250-11250/com.android.player W/MBServiceCompat: removeSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.519 11250-11250/com.android.player W/MBServiceCompat: addSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.525 11250-11250/com.android.player W/MBServiceCompat: removeSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.525 11250-11250/com.android.player W/MBServiceCompat: addSubscription for callback that isn't registered id=hhhh
Update 2
Also there
https://github.com/googlesamples/android-UniversalMusicPlayer/issues/92
mb last comment of this link will solve this problem for me too
Update 3
Yeah, github.com/googlesamples/android-UniversalMusicPlayer/issues/92#issuecomment-287668132 SOLVED the problem:
move MediaBrowserCompat.connect() from onStart() to onCreate(), and move MediaBrowserCompat.disconnect() from onStop() to onDestroy(). It works now.