I don’t see why you need to cancel a request on rotation.
Mike Nakhimovich

One way around this would perhaps be making your observable aHot Observable by calling publish().autoConnect() on it. Then unsubscribing would have no effect on it as it would still emit items even if no one is listening. If the user rotates the device or even goes to another activity your request would still be executed. You can save the incoming data on the db using onNext and fetch from there the next time that it is requested, something like:

.doOnNext(data -> saveToDb(data))
.startWith(databaseObservable).takeFirst(data -> !data.IsStale())

Note that the network request won’t be executed if the db has valid data.

This is what I’m doing in production but I’m by no means an expert on the subject so take this with a grain of salt

Show your support

Clapping shows how much you appreciated Fernando Raviola’s story.