New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback method called multiply times #80
Comments
Well you can use this method to do it =) Just like this: Subscription loadTeasersSubscription;
public void loadTeasers(int skip, boolean refresh, Category category) {
if (loadTeasersSubscription != null && !loadTeasersSubscription.isUnsubscribed()) {
loadTeasersSubscription.unsubscribe();
}
getViewState().showProgress();
loadTeasersSubscription = ActiveAndroidHelper.getSources()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(teasers -> {
getViewState().onTeasersLoaded(teasers);
getViewState().hideProgress();
}, this::onError);
unsubscribeOnDestroy(loadTeasersSubscription);
} |
@senneco Nope, this does not work. That was only a guess about necessity to unsubsribe. |
It seems that I didn't understand what is your problem. Problem is that this method call each time after onResume, or problem that it's not? Or something else? |
What strategy do you use for Looks like you use default strategy. So it can be following behavior:
@senneco can you correct me if I am wrong with Moxy lifecycle? |
I just call loadTeasers() each time my fragment executes OnResume method. |
@lectricas it seems like bug is in your |
@senneco
Seems like callback method is called by its own. Presenter calls callback method correctly - single time on each subscribe. |
@lectricas could you provide me your MvpView interface? |
|
@lectricas try to apply AddToEndStrategy, like this: @StateStrategy(AddToEndSingleStrategy.class)
public interface BaseNewsViewState extends BaseViewState {
void onTeasersLoaded(List<Teaser> teasers);
void onTeasersQueried(List<Teaser> teasers);
void onCurrencyLoaded(CurrencyRequestAnswer currencyAnswer);
void integerTest(Integer integer);
} |
Better now, but first callback is kinda redundant. |
I think |
@A-Zaiats |
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
The text was updated successfully, but these errors were encountered: