sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

Fragment's Presenter onDestroy(false) not called #260

Closed DrobyshevAlex closed 6 years ago

DrobyshevAlex commented 7 years ago

In continuation to #257

  1. App run
  2. App -> setFragment LogoFragment (without add in BackStack)
  3. App -> setFragment HomeFragment (with addToBackstack)
  4. LogoPresenter.detachView(true). This is wrong!
  5. Press Back Button
  6. HomePresenter.detachView(false). This is correct.
sockeqwe commented 7 years ago

Ok, the Problem was introduced with the lifecycle change of #257 to onStop() (was onDestroyView() before). I have to rethink the solution of #257 or maybe introduce breaking API changes (see #262)

DrobyshevAlex commented 7 years ago

Why not just call in MviBaseFragment detachView(false) in Fragment.onDestroy()?

sockeqwe commented 7 years ago

because attachView() is called possible more often (since invoked in onStart()) then detachView() (called in onDestroy() )

DrobyshevAlex commented 7 years ago

count of onStart == count of onStop?

if take version 3.0.4 and make like

public abstract class BaseFragment<V extends MvpView, P extends MviPresenter> extends MviFragment {
    protected P presenter;
    private boolean isAttached = true;

    @Override
    public void onStart() {
        super.onStart();
        if (presenter != null && !isAttached) {
            presenter.attachView(this);
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        if (presenter != null && isAttached) {
            presenter.detachView(true);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        presenter.detachView(false);
    }
}

257 and #260 both work fine

since 3.0.5 i make simple

public abstract class BaseFragment<V extends MvpView, P extends MviPresenter> extends MviFragment {
    protected P presenter;

    @Override
    public void onDestroy() {
        super.onDestroy();
        presenter.detachView(false);
}

My app work is right. unsubscribe work

sockeqwe commented 6 years ago

See #274. Feel free to reopen this issue if 3.1.0 (snapshot) doesn't solve this porblem.