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

Hex crashes when device is rotated #9

Closed
RyanRiddle opened this issue Aug 19, 2016 · 3 comments
Closed

Hex crashes when device is rotated #9

RyanRiddle opened this issue Aug 19, 2016 · 3 comments
Labels

Comments

@RyanRiddle
Copy link

If I rotate my Nexus 5 while I am viewing an article or the comments, Hex crashes. "Unfortunately, Hex has stopped."

Rotating the device is not a problem if I am viewing the first page.

Steps to reproduce:
Open Hex.
Choose a link.
When the article has loaded, rotate the device.
Hex crashes.

It also crashes if you are viewing the comments.
It also crashes if you are viewing the front page in landscape orientation, choose an article, and the rotate the device to portrait orientation.

My device is a Nexus 5.

@RyanRiddle
Copy link
Author

It looks like an activity fragment is going stale during the activity lifecycle. https://developer.android.com/guide/topics/resources/runtime-changes.html

When the orientation changes, the StoryActivity is destroyed and recreated but some part of the ArticleFragment is going bad during one of the state changes.

The article I linked suggest two ways of dealing with this. Both options would prevent a page refresh which I think is a win.

The easiest thing to do is say you will manually handle the orientation change in your manifest. All you have to do is add this attribute value pair to the activity tag for the StoryActivity. android:configChanges="orientation|screenSize"

The article says this is not recommended because it makes it "more difficult to use alternative resources". I'm not sure alternative resources are needed.

The alternative is to let the app restart the activity like normal but store the data you need in a stateful object. I'm not sure which members you would need to store. Maybe just the mPagerAdapter containing the article fragment.

Let me know what you think. I can send you a pull request if needed.

@longdivision
Copy link
Owner

Hey @RyanRiddle - thanks for raising this and providing so much detail :)

Apologies for the bug! I raised a fix for this in #10 and deployed in v0.1.5. The new version has been pushed to the Play Store and should live in the next few hours.

To fix this for the front page I bundle up and restore the state in FrontPageActivity. For the article/comments view I settled on using android:configChanges="orientation|screenSize" for StoryActivity for now as bundling the state here needs a little more thought/work. This has resolved all but one rotation issue AFAICT (but let me know if not).

I can send you a pull request if needed.

Pull requests are always welcome on this project! There was nothing written down to document this so I've added some contribution guidelines to the project.

@RyanRiddle
Copy link
Author

Thanks for getting this fixed so quickly! I downloaded the latest version
and verified the fix.

I could not reproduce issue #11 but if I run into it later I might take a
crack at it.

Good job on this app! Works great and the code is a pleasure to work with.

Ryan

On Sat, Aug 20, 2016 at 9:59 AM Sean Powell [email protected]
wrote:

Closed #9 #9.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ADChKWmOpOzO15BdP2oJCtzoUaO-DPKSks5qhwhBgaJpZM4JoaeE
.

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