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 @ 2024-01-17 16:46  听着music睡  阅读(222)  评论(0编辑  收藏  举报