Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Why does FunFact Android app reset itself on an actual phone?

I just completed the Testing and Debugging stage of the Build a Simple Android App course. In the last part of that section the presenter talks about running your app on an actual phone. My phone is a Google Nexus 5 running Lollipop. I was able to connect the phone and the app runs on it as described in the video. I have noticed that whenever I rotate the phone the app restarts itself. What would cause this to happen?

2 Answers

I have been testing on a different phone but I have not noticed this problem. This would be a great chance for you to do some troubleshooting on your app. I have searched google and found this StackOverflow question which might help.

http://stackoverflow.com/questions/5913130/dont-reload-application-when-orientation-changes

The accepted answer has three solutions. I would use the third one myself because it seems simple and straighforward.

The solution Ben Hollands suggests is the second on the accepted answer and a great alternative.

The link was very helpful. I found an answer further down the page, one of the non-accepted answers, which did the trick for me. The answer from Josue Rocha advised adding a line to the XML in AndroidManifest.xml.

android:configChanges="orientation|screenSize"

Doing this worked for me.

Thats great to hear! Glad I at least pointed you in the right direction.

Goodluck with your projects! --Ricky

Hello i had the same problem , i think this is just a rendering problem because the app was originally made for Portrait? Maybe you can fix the orientation in the Android Manifest file with?

android:screenOrientation="portrait"

It works, thanks. But I'd like to learn how to enable rotation for my app, of course without restart the app.