1

I have two layouts for one activity like layout-port and layout-land, with different designs. If the user clicks the button in portrait mode and changes to landscape mode, the activity restarts or refreshes again. Can anybody tell me how to avoid this? Can anybody tell me how to maintain the state activity? Can anybody provide an example?

Thanks in advance

Illidanek
  • 996
  • 1
  • 18
  • 32
mohan
  • 13,035
  • 29
  • 108
  • 178

1 Answers1

0

When the Activity goes from portrait to landscape the onCreate method is executed again, thus creating the button again. Thus, you should store the state of the button.

The best way is to use the onSaveInstanceState(Bundle) in order to store the state of the button. Then, when the Activity is created again, you should check the bundle and configure your layout accordingly. For more information, please check here: http://developer.android.com/reference/android/app/Activity.html (Section: Configuration changes).

Hope this helps!!

Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54