RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.81k stars 405 forks source link

toSingle() is creating new thread everytime #365

Open SAGARSURI opened 5 years ago

SAGARSURI commented 5 years ago

Hi @Diolor

I am using the RxJava2 adapter. I saw one issue here. When I do subscribeOn(Schedulers.io()). It will use new thread every single picture I take. This can slow the app in some point of time. Here is my code:

fotoapparat
        .autoFocus()
        .takePicture()
        .toBitmap()
        .toSingle()
        .map {
          Timber.e(Thread.currentThread().name)
          it.bitmap.rotate(-it.rotationDegrees.toFloat())
        }
        .subscribeOn(Schedulers.computation())
        .observeOn(AndroidSchedulers.mainThread())
        .doOnSuccess { MediaActionSound().play(MediaActionSound.SHUTTER_CLICK) }
        .subscribe({
          Timber.e("Image Clicked")
          userImage = it
          previewCapturedImage(it)
        }, {
          Timber.e(it.message)
        })

If you see the logcat. You will find this:

RxComputationThreadPool-1
RxComputationThreadPool-2
RxComputationThreadPool-3

How can I use a single computation thread or limit the creation of new thread every time? I am using the latest release i.e 2.7.0