AkshayChordiya / News

A sample News 🗞 app built using Modern Android Development [Architecture Components, Coroutines, Retrofit, Room, Kotlin, Dagger]
MIT License
849 stars 168 forks source link

NetworkBoundResource.asFlow() is called multiple times #38

Closed kefasjw closed 4 years ago

kefasjw commented 4 years ago

After 5 seconds of no active observers for NewsArticleViewModel.newsArticles (device locked) and NewsActivity re-observe the newsArticles (device unlocked), NetworkBoundResource.asFlow() is called again.

If I change the emitAll(loadFromDb().map { ViewState.success(it) }) into emit(loadFromDb().map { ViewState.success(it) }.first()), NetworkBoundResource.asFlow() is not called.

AkshayChordiya commented 4 years ago

Fixed with https://github.com/AkshayChordiya/News/commit/d445be8a0d139527f15656a1c7b5f238fd1b05c7