Skip to content Skip to sidebar Skip to footer

MediaBrowser.subscribe Doesn't Work After I Get Back To Activity 1 From Activity 2 (6.0.1 Android)

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

Solution 1:

  1. This issue was marked as fixed at google issuetracker in Support Lib v 25.4.0
  2. solution to

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

works for me.

  1. when I moved them and fixed the original issue, the next one appeared: MediaController Callback didn't work. It seems for me as caused by the similar bug. So I have moved call to unsubscribe() to onDestroy() too, and everything works now.

So my code now looks like:

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();
    }
}

Solution 2:

Temporary solution:

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

Must be fixed in v25.4.0: https://issuetracker.google.com/issues/37133265#comment3


Solution 3:

With reference to Google issue tracker.

Issue is fixed and released in 25.4.0 version of support library.

If any issue persists, please report at Google issue tracker they will re-open to examine.


Post a Comment for "MediaBrowser.subscribe Doesn't Work After I Get Back To Activity 1 From Activity 2 (6.0.1 Android)"