使用RXJava缓存可观察对象。 Android的

时间:2017-04-13 07:40:51

标签: android rx-java rx-java2

我有一个observable,它使用不同的filePath异步加载图像,我想缓存位图变量。我只是尝试添加.cache方法,但它没有帮助。如何在ma中完成缓存?

Observable.fromCallable(() -> {
    File outputFile = new File(filePath);
    Bitmap bitmap = decodeSampledBitmapFromUrl(newTAG, width, height);
    return bitmap;
})
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(bitmap -> {
                    mImageView.setImageBitmap(bitmap);
                },
                throwable -> {
                    //handle it
                });

2 个答案:

答案 0 :(得分:2)

使用GlidePicasso及其内置缓存功能,也可以考虑使用WeakReferences来存储类似的位图。

答案 1 :(得分:0)

你的意思是在你显示的代码后使用位图变量?如果您不使用它,则应拨打Bitmap.recycler()

相关问题