使用 RXJava 可观察到的缓存。 Android
Caching observable with RXJava. Android
我有一个 Observable,它使用不同 filePath
异步加载图像,我想缓存位图变量。我试着只添加一个 .cache
方法,但它没有帮助。 ma case如何实现缓存?
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
});
你的意思是在你显示的代码后使用位图变量?如果你不使用它,你应该调用 Bitmap.recycler()
.
使用 Glide
或 Picasso
及其内置的缓存功能,同时考虑使用 WeakReferences 来存储这样的位图。
我有一个 Observable,它使用不同 filePath
异步加载图像,我想缓存位图变量。我试着只添加一个 .cache
方法,但它没有帮助。 ma case如何实现缓存?
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
});
你的意思是在你显示的代码后使用位图变量?如果你不使用它,你应该调用 Bitmap.recycler()
.
使用 Glide
或 Picasso
及其内置的缓存功能,同时考虑使用 WeakReferences 来存储这样的位图。