R
R
Rarity72020-01-22 15:29:36
Android
Rarity7, 2020-01-22 15:29:36

How to save Bitmap to file asynchronously?

I want to save a Bitmap to a file. I do it through FileOutputStream. On StackOverflow they write that such operations need to be done asynchronously. I want to know if this can be achieved with the help of RxJava? If so, can you show me how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AntonKrygin, 2020-01-23
@Rarity7

Yes, it's better to do it in the background. More or less like this:

Disposable d = Observable.fromCallable(() -> {
    // save bitmap
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();

And don't forget to call d.dispose() in the onDestroy() method of your activity or fragment.
P.s. I haven't checked the code, I'm writing from memory on my phone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question