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

Avoid restarting and restore state after performing landscape #20

Closed
AkshayChordiya opened this issue Mar 7, 2016 · 10 comments
Closed

Comments

@AkshayChordiya
Copy link

When the phone is rotated into landscape the material-intro not only starts from the beginning, it creates a new instance of all the slides that is the intro is showed 2 times.

@janheinrichmerker
Copy link
Owner

I can't reproduce this behavior on my devices. Which library version and which device are you using?

@AkshayChordiya
Copy link
Author

I'm using SNAPSHOT of material-intro.

​Regards
,
​Akshay Chordiya

On Mon, Mar 7, 2016 at 8:11 PM, Heinrich Reimer notifications@github.com
wrote:

I can't reproduce this behavior on my devices. Which library version and
which device are you using?


Reply to this email directly or view it on GitHub
#20 (comment)
.

@Maxr1998
Copy link
Contributor

For me, it doesn't show the startup two times, but he is right with recreation. The FragmentManager normally cares about retaining Fragments, etc. This is broken with this library, which means Fragments are recreated each rotation, and that wastes power and CPU cycles.

I think it will be pretty difficult adding proper fragment retaining support, but it will be worth it ;D

@Maxr1998
Copy link
Contributor

Fun fact: if you rotate the device, the Fragments get recreated, but onCreateView doesn't get called, means permissionGranted is false, and doesn't get true, means you can't go forward anymore after rotation.

@Maxr1998 Maxr1998 mentioned this issue Mar 22, 2016
@Maxr1998
Copy link
Contributor

Sadly, my fix doesn't fix the problem of my last comment. So we definitely need to rewrite the IntroActivity for proper instance saving and restoring support.

@janheinrichmerker
Copy link
Owner

I switched from using FragmentPagerAdapter to using FragmentStatePagerAdapter in e6fe290. This should keep Fragments in memory. I have to look into restoring pager position though.

@janheinrichmerker
Copy link
Owner

The main issue is that the displayed Fragment is the old one loaded from FragmentManager and the code that checks if users are allowed to go to the next page is the new one returned because onCreate() gets called on IntroActivity

@janheinrichmerker
Copy link
Owner

We could either try to detect if an old but matching Fragment is already existing in FragmentManager in SlideAdapter.addSlide(). But that would require us to save a unique ID with every Slide which I don't like as it's extra effort for developers implementing this library ...
... or we simply don't use Fragment retaining at all but instead create every Fragment again after an orientation change. That's not a problem in particular as the fragments used in an intro won't be very complicated and thus the recreation process would not take too much time...

@janheinrichmerker
Copy link
Owner

(Accidentially closed the issue. Sorry for that!)

@janheinrichmerker
Copy link
Owner

Finally found a solution for the first approach without requiring an ID. Needs some polishing and will be a breaking change so stay tuned for a fix soon.

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

No branches or pull requests

3 participants