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 is it when you change the orientation on the Fun Facts App that it seems to reset itself?

For example, if you click the button a few times and get a different color and fact and then switch the orientation, it then resets to the hard coded activity layout. Can someone explain why this happens?

Thanks!

2 Answers

Hi Anthony.

When you tilt your phone from portrait to landscape android actually closes your current activity and creates another in the relevant orientation. You can obviously code the app to continue (as most apps do) by making use of the methods called during the activity life cycle.

http://developer.android.com/training/basics/activity-lifecycle/index.html

Another approach is to force android to stay in one particular orientation (which i prefer for this app), you can do this by going to the android manifest and selecting your main activity to the right there will be a list of options go to Orientation and select portrait. If done correctly the app will now not change your current perspective when you tilt your phone and will therefore not restart your progress.

Hope this helps

Daniel

Thanks! I read through the activity life cycle article and I feel I have a better understanding.