Android项目实战(六十九):Matisse知乎图片选择,切换相册不显示图片的bug

问题现象:

正常显示默认的所有的图片,当点击切换相册的时候,相册的图片是空的

因为项目已经不再维护,故下载源码,import module到项目中

修复步骤:

1、MatisseActivity

复制代码
private void onAlbumSelected(Album album) {
        if (album.isAll() && album.isEmpty()) {
            mContainer.setVisibility(View.GONE);
            mEmptyView.setVisibility(View.VISIBLE);
        } else {
            mContainer.setVisibility(View.VISIBLE);
            mEmptyView.setVisibility(View.GONE);
            Fragment fragment = MediaSelectionFragment.newInstance(album);

            // 修复matisse源码存在的,切换其他相册空白问题
            Fragment oldFragment = getSupportFragmentManager().findFragmentByTag(MediaSelectionFragment.class.getSimpleName());
            if (oldFragment instanceof MediaSelectionFragment) {
                MediaSelectionFragment newFragment = (MediaSelectionFragment) oldFragment;
                newFragment.destroyManagerLoader();
            }

            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.container, fragment, MediaSelectionFragment.class.getSimpleName())
                    .commitAllowingStateLoss();
        }
    }
复制代码
@Override
    protected void onDestroy() {
        super.onDestroy();
        mAlbumCollection.onDestroy();
        mSpec.onCheckedListener = null;
        mSpec.onSelectedListener = null;
    }

 

 

2、MediaSelectionFragment

public void destroyManagerLoader() {
        mAlbumMediaCollection.onDestroy();
    }

3、AlbumMediaCollection

 public void onDestroy() {
        if (mLoaderManager != null) {
            mLoaderManager.destroyLoader(LOADER_ID);
        }
        mCallbacks = null;
        mLoaderManager = null;
    }

 

posted @   听着music睡  阅读(240)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2020-01-17 Android项目实战(五十九):调试方法神器Hugo
2015-01-17 安卓开发_浅谈自定义组件
点击右上角即可分享
微信分享提示