RxJava Observable stream inside doWork of WorkManager's Worker

Viewed 485

I have a sync process with multiple Observables chained which I would like to call as a background service at a specific time.

I used to do this in a Service since now, but with the Android Oreo limitation, this is not possible anymore, so instead of choosing Job Scheduler + JobDispatcher for backward compatibility (min SDK supported is 19), I changed the Service class with a Worker (androidx.work).

Q1: How can I make the doWork's result be triggered only after the stream is closed (/make it synchronously)?

Q2: I need to close the whole stream (dispose of the sync subscription) manually on a specific action made by the user.

I tried doing that in "onWorkFinished" callback given by Worker class, but since the doWork returns the Result before the stream it's finished, this is not an option. I could inject the worker where I need to do this, but returning a Result before the whole job it's done doesn't sound like a good practice either.

Any suggestions are welcomed. Thanks!

0 Answers
Related