Closed 0xGuybrush closed 4 years ago
Hi,
Thanks for reporting issue. I suppose this problem may be related to the fact that there is more than one Disposable per from the ReactiveNetwork single Activity and the same objects could reused. Due to this fact, when NetworkCallback is unregistered once, then another one cannot be unregistered because of the same object. I'm not sure about that, but that's my guess.
Regards, Piotr
Hi Piotr,
thanks for your reply & getting back so quickly.
I have multiple pieces of functionality that depend on network state in some of my activities, so thought the cleanest way was to reuse, but I'll see if I can refactor it though to use a single disposable instead.
Best Dave
Just to note, if anyone else comes across this, that I now think the correct way of reusing this in RxJava is to turn it into a ConnectableObservable
to allow multiple observables to chain to it and will only dispose when the final downstream Observable disconnects.
I've used .share()
here to handle this and seems to be working fine to turn it into a "hot" observable. Closing ticket, as it's due to my knowledge gap rather than an issue here 🙂
Great! I'm glad you solved this issue. :)
Describe the bug
Subscribing to a single "internet connectivity check" from two different disposables causing an
IllegalArgumentException
when disposing obserable chains on pause.To Reproduce Steps to reproduce the behavior:
onPause
Boot app and trigger onPause (activity change or hide app)
Results in error:
Expected behavior Expected additional subscribers to observable to be disposed of without issue. (New to RxJava though, so may be my misunderstanding!)
Additional context Tried to create a complete example here — another-dave/reactive-network-test