Sree
Sree

Reputation: 2787

Is there a way in RxJava/RxAndroid to let the chain of operators finish even after unsubscribing?

Basically I have a chain where I call my API and it returns back a result which I use to update my local database. Finally, after that's done, I have code in my onNext() to update the UI. If the user closes the activity, I need to call unsubscribe but that might mean that my database might not update. Is there a way to ensure that?

Upvotes: 1

Views: 155

Answers (1)

akarnokd
akarnokd

Reputation: 70007

Yes, you can use doOnNext().publish().autoConnect(). The doOnNext should have the database save logic and the rest makes sure it runs to completion even if the Subscriber unsubscribed.

Upvotes: 1

Related Questions