I'm using rxAndroid with an MVVM architecture. In my Activity, I need to bind my streams then fetch data from the server, which will eventually call the downstream.
My reasoning is the following:
- I need to unsubscribe my streams in onStop()
(onDestroy
can cause memory leaks).
-> therefore I need to subscribe to them in onStart()
(otherwise coming back from background doesn't recreate the stream).
-> therefore I need to fetch my data in or after onStart()
, because the stream has to be bound before I can start calling the upstream.
But in this case, every time I come back to the app after background, it's going to call the fetch method, which is not a behavior I want. Ideally I'd like to call the fetch method once, for example in onCreate()
.
How can I nicely deal with this problem? I've tried finding solutions on SO and other websites but no luck.