MediaBrowser.subscribe doesn't work after I get back to activity 1 from activity 2 (6.0.1 Android)

后端 未结 3 355
鱼传尺愫
鱼传尺愫 2021-01-19 07:49

When I open activity 1 (Main/Launcher activity of the app), that includes MediaBrowser connection, MediaBrowser.subscribe works ok (onChildrenLoaded

相关标签:
3条回答
  • 2021-01-19 08:22
    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();
        }
    }
    
    0 讨论(0)
  • 2021-01-19 08:26

    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.

    0 讨论(0)
  • 2021-01-19 08:30

    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

    0 讨论(0)
提交回复
热议问题