MediaBrowser.subscribe not working after i go back to activity 1 from activity 2 (6.0.1 Android)

When I open Activity 1 (main / Launcher app activity) that includes the MediaBrowser connection, it MediaBrowser.subscribe

works fine ( onChildrenLoaded

called after it), but when I opened another activity (number 2) from Activity 1 (with a button click and a push button push), and then close this activity 2 MediaBrowser.subscribe

stops working - onChildrenLoaded

DOES NOT TURN OFF after subscribing, so after activity 2 finishes onConnected

SubscriptionCallback (activity 1) and mMediaBrowser.subscribe(MEDIA_ID_ROOT, mSubscriptionCallback);

but my items are not updated because it onChildrenLoaded

never starts

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 fine for 4.4.4 Android (no such problem)

Update

I seem to have found this issue on Google Bugs (some devs reported this): 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

There is also an error like this:

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

There is also

https://github.com/googlesamples/android-UniversalMusicPlayer/issues/92

mb Last comment from this link will solve this problem for me too

Update 3

Yes, github.com/googlesamples/android-UniversalMusicPlayer/issues/92#issuecomment-287668132 SOLVES the problem:

move MediaBrowserCompat.connect () from onStart () to onCreate () and move MediaBrowserCompat.disconnect () from onStop () to onDestroy (). It works now.

+3


source to share


3 answers


Temporary solution:

move MediaBrowserCompat.connect () from onStart () to onCreate () and move MediaBrowserCompat.disconnect () from onStop () to onDestroy (). It works now.



Should be fixed in version 25.4.0: https://issuetracker.google.com/issues/37133265#comment3

0


source


move MediaBrowserCompat.connect () from onStart () to onCreate () and move MediaBrowserCompat.disconnect () from onStop () to onDestroy ()

works for me.



  1. When I moved them around and fixed the original problem the following appeared: MediaController Callback

    didn't work. It seems to me that this is caused by a similar error. So I moved the call to unsubscribe()

    on onDestroy()

    too, and now everything works.

So now my code looks like this:

protected void onCreate(Bundle savedInstanceState) {
    ...    
    mediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, AudioService.class),
            connCallbacks,
            null);
    mediaBrowser.connect();
    ...
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    MediaControllerCompat cntrlr = MediaControllerCompat.getMediaController(this);
    if(cntrlr != null) {
        cntrlr.unregisterCallback(cntrlrCallback);
    }
    if(mediaBrowser.isConnected()) {
        mediaBrowser.unsubscribe(mediaBrowser.getRoot());
        mediaBrowser.disconnect();
    }
}

      

0


source


Regarding Google Issue Tracking .

The issue has been fixed and released in the 25.4.0 version of the Support Library .

If any issue persists, please report to Google's tracker , which they will open for review.

0


source







All Articles