从活动2(6.0.1 Android)返回活动1后,MediaBrowser.subscribe无法正常工作 [英] MediaBrowser.subscribe doesn't work after I get back to activity 1 from activity 2 (6.0.1 Android)

查看:73
本文介绍了从活动2(6.0.1 Android)返回活动1后,MediaBrowser.subscribe无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开包括MediaBrowser连接的活动1(应用程序的Main/Launcher活动)时, MediaBrowser.subscribe 正常工作(之后将调用 onChildrenLoaded ),但是当我从活动1中打开其他活动(数字2)(使用按钮单击侦听器和意图)然后关闭此活动2时, MediaBrowser.subscribe 停止工作- onChildrenLoaded ,因此活动2完成(活动1的)SubscriptionCallback的 onConnected 后, mMediaBrowser.subscribe(MEDIA_ID_ROOT,mSubscriptionCallback); 被调用,但是我的项目没有更新,因为 onChildrenLoaded 从未触发

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

但是对于4.4.4 Android来说可以正常运行(没有此类问题)

But it works ok for 4.4.4 Android (no such problems)

更新

似乎我在Google Bugs上发现了此问题(一些开发人员报告了此问题): 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

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

但是没有解决办法

也有这样的错误:

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

更新2

也有

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

此链接的最后评论也将为我解决此问题

mb last comment of this link will solve this problem for me too

更新3

是的,github.com/googlesamples/android-UniversalMusicPlayer/issues/92#issuecomment-287668132解决了该问题:

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

将MediaBrowserCompat.connect()从onStart()移到onCreate(),然后将MediaBrowserCompat.disconnect()从onStop()移到onDestroy().它现在可以工作.

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

推荐答案

临时解决方案:

将MediaBrowserCompat.connect()从onStart()移到onCreate(),然后将MediaBrowserCompat.disconnect()从onStop()移到onDestroy().它现在可以工作.

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

必须在v25.4.0中修复: https://issuetracker.google.com/issues/37133265#comment3

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

这篇关于从活动2(6.0.1 Android)返回活动1后,MediaBrowser.subscribe无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆