0

I'm trying to create a DatabaseHelper class to separate out some Room things. DatabaseHelper is not an Activity or Fragment. I'm trying to do something like the following

 roomDb.mediaItemDownloadDao()
            .findById(mediaItemId)
            .subscribeOn(Schedulers.io())
            .subscribe(oldDownload -> {
                oldDownload.setSomeField(true);
                roomDb.mediaItemDownloadDao().insert(oldDownload);
            });
}

but it tells me the result of subscribe is not used. is there a way to make sure that is executed and then dispose immediately ? should i be passing the disposable up to the caller? whats the best way to accomplish what i want / use rx objects outside of a fragment / activity ?

1tSurge
  • 663
  • 2
  • 7
  • 20

2 Answers2

0

so i think instead of going to RX for this i want to use

 rx.schedulers.Schedulers.io().createWorker()

and just put the work in there =]

1tSurge
  • 663
  • 2
  • 7
  • 20
0

This question is similar to yours. I would add that you should add your subscription Disposable to a CompositeDisposable in your helper, and when the parent Activity is destroyed, chain down a call to dispose your CompositeDisposable.

urgentx
  • 3,832
  • 2
  • 19
  • 30
  • I was more so looking at how to do this in the case of a download service, so i think removing the need for a composite/activity/etc and going with schedulers is the path i want. – 1tSurge May 25 '18 at 20:24