Callback method called multiply times
See original GitHub issuepublic void loadTeasers(int skip, boolean refresh, Category category) {
getViewState().showProgress();
Subscription s2 = ActiveAndroidHelper.getSources()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(teasers -> {
getViewState().onTeasersLoaded(teasers);
getViewState().hideProgress();
}, this::onError);
unsubscribeOnDestroy(s2);
}
Suppose we have simple method which loads some data from network. I want to refresh my network data every onResume method. And, in this case, on each call of loadTeasers(true, new Category()), the callback method onTeasersLoaded(teasers) is called N times, where N is the number of onResume methods (and loadTeasers) executed. I think I need to unsubscribe and null the previous subsribition, but which method to use here? Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Callback Function executing multiple times - Stack Overflow
Every time getInput is called, you're push ing to the allUserDdata array, and then the whole allUserData is piped to callback .
Read more >How to prevent disasters caused by the callback getting called ...
are you sure, the callback is called several times? sounds like the a callback is attached several time to me. this can happen...
Read more >callback function called multiple times #558 - GitHub
While trying to invoke bulk API, we found that callback function is getting invoked multiple times. Not sure if this is by design...
Read more >Help with resolving call multiple times (Call keepAlive)
The method you're implementing is of type 3 (callback) as described in Method Types. So you need to declare it as such in...
Read more >How to prevent a function from being called multiple times?
In this article you'll find out how to use throttle and debounce to prevent the callback or function fired too quickly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What strategy do you use for
onTeaserLoaded(teasers)
method? Was your view stopped before resume? Are you sure thatonTeaserLoaded(teasers)
method is called N times fromsubsrciber#onNext
callback?Looks like you use default strategy. So it can be following behavior:
onTeaserLoaded(teasers)
that was called before)onTeaserLoaded(teasers)
was called byloadTeasers
callback@senneco can you correct me if I am wrong with Moxy lifecycle?
@A-Zaiats woohoo works as desired. Thanks.