Skip to content
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

ViewPager on back stack calls Presenter's method detachView(retainInstance=true) #271

Closed
Thomas-Vos opened this issue Aug 28, 2017 · 3 comments
Labels

Comments

@Thomas-Vos
Copy link
Contributor

Hi Hannes,

I'm having some issues with a ViewPager in the back stack.

Mosby Version:
mvp-common:3.0.4 and viewstate:3.0.4

Expected behavior
I have a Fragment called A that contains a ViewPager that contains Fragments B and C. When Fragment A is put on the back stack, the method detachView(retainInstance=false) gets called. At the same time, detachView(retainInstance=false) is supposed to be called for Fragments B and C.

Actual behavior (include a stacktrace if crash)
When Fragment A is put on the back stack, the following happens:

  • Fragment A Presenter: detachView(retainInstance=false)
  • Fragment B Presenter: detachView(retainInstance=true)
  • Fragment C Presenter: detachView(retainInstance=true)

As you can see, retainInstance is true for both B and C, but it should be false.

Steps to reproduce the behavior or link to a sample repository

  1. Create Fragment A containing a ViewPager that contains Fragments B and C.
  2. All Fragments call setRetainInstance(true) in the onCreate() method.
  3. The MVP delegate is instantiated like this: new FragmentMvpViewStateDelegateImpl<>(this, this, true, false);.
  4. Now put Fragment A on the backstack and see what happens.

Thanks, Thomas

@sockeqwe
Copy link
Owner

sockeqwe commented Aug 28, 2017

Hey,
I see ... This bug seems to occur if you have setRetainInstance(true) and `new FragmentMvpViewStateDelegateImpl<>(..., keepPresenterAndViewStateOnBackstack = false)´ so you don't want to keep the presenter.

Beside that this is a bug (thanks for reporting),
what is actually the reason behind using setRetainInstance(true) in that case? Does it work as expected with setRetainInstance(false)?

@sockeqwe sockeqwe added the bug label Aug 28, 2017
@Thomas-Vos
Copy link
Contributor Author

Thomas-Vos commented Aug 29, 2017

Hello @sockeqwe, I want to keep the presenter on a configuration change, that's why I call setRetainInstance(true). I just tried without calling setRetainInstance(true); the presenter is not retained anymore on a configuration change, and I'm still having the same issue.

If I return to Fragment A (by pressing back or popping the back stack), the presenter is recreated anyway, so that's why I set keepPresenterAndViewStateOnBackstack to false. (issue #265)

I also noticed if you remove Fragment A from the back stack (go "up"), then Fragment B/C call detachView(retainInstance=true). I currently have worked around this by calling detachView(false) manually in the Fragment's onDestroy(). Is this a bug?

Thanks for your help,
Thomas

sockeqwe added a commit that referenced this issue Sep 5, 2017
@sockeqwe
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants