Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Fix view beeing null before unsubscribing from Subscriptions #27

Merged

Conversation

passsy
Copy link
Contributor

@passsy passsy commented Oct 25, 2016

When using the RxTiPresenterSubscriptionHandler to automatically unsubscribe from views it can happen that getView() is already null before Subscriptions#unsubscribe() is called. This is caused by the VIEW_DETACHED lifecycle event after super is called after mView is set to null. Changing the order fixes the Problem.

From sample HelloWorldPresenter.java

    @Override
    protected void onAttachView(@NonNull final HelloWorldView view) {
        super.onAttachView(view);

        rxSubscriptionHelper.manageViewSubscription(mText.asObservable()
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(final String text) {
                        // getView() can be null before this Observer is unsubscribed
                        getView().showText(text);
                    }
                }));
    }

@StefMa StefMa merged commit ef4ed67 into master Nov 4, 2016
@StefMa StefMa deleted the bugfix/view_is_null_before_subscriptions_are_unsubscribed branch November 4, 2016 08:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

2 participants