question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Callback method called multiply times

See original GitHub issue
public 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:closed
  • Created 7 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
A-Zaiatscommented, Jan 23, 2017

What strategy do you use for onTeaserLoaded(teasers) method? Was your view stopped before resume? Are you sure that onTeaserLoaded(teasers) method is called N times from subsrciber#onNext callback?

Looks like you use default strategy. So it can be following behavior:

  • the View was stopped
  • the View was detached from presenter
  • the View was attached to the Presenter
  • the ViewState restored state (called all onTeaserLoaded(teasers) that was called before)
  • one more onTeaserLoaded(teasers) was called by loadTeasers callback

@senneco can you correct me if I am wrong with Moxy lifecycle?

0reactions
lectricascommented, Jan 23, 2017

@A-Zaiats woohoo works as desired. Thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found