Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Android portrait and landscape in code?

Tags:

java

android

I'm developing an application in two languages (Arabic and English), When the user press on a Button in the first activity it views another activity contains (Timer, array of strings and many different values)
When the user change between portrait and landscape the values lost, How to handle this problem (Keeping the values and the objects)

Kind Regards,

like image 687
Mohammad Abu Hmead Avatar asked Dec 27 '11 15:12

Mohammad Abu Hmead


1 Answers

When you rotate a device your activity is restarted. To avoid this, you must handle the orientation change yourself. To do this, you must add the configuration to your manifest XML (android:configChanges) and override the onConfigurationChanged function in your activity.

Here's an example from the Android documentation. Implementing this will allow you to retain the state (and variables) in your activity during an orientation change.

like image 132
jlindenbaum Avatar answered Oct 24 '22 04:10

jlindenbaum