Hii
I want to know the mechanism how the screen changes automatically from horizontally to vertically or vice-versa in android when we change the position of phone. Example in terms of coding would be highly appreciable.
Regards
Piyush
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Screen is changed automatically from Portrait to Landscape and vice versa. So, in the most simple case you do not have to do anything. However, there is one important thing to take into account:
On orientation change, Android terminates your current activity and re-creates it again. So, if you have some important state variables, you must preserve them. In order to do that, you must override the function
When instance is re-created, you have to check
value of
savedInstanceState. If it is null, it is first start. If it is not null, then it is re-creation caused by rotation, and you have to fetch state variable values from BundlesavedInstanceState.If you need different layouts for Portrait/Landscape please check answer from Anand.