0

In android, when the device's orientation changes, the activity is destroyed and recreated. Is there a way to prevent this from happening without preventing orientation changes in the android manifest?

Glenn
  • 12,741
  • 6
  • 47
  • 48

2 Answers2

0

In your manifest for the main activity, add the line

android:configChanges=<x>

where x is the type of change you want to handle in your activity. For orientation, use "orientation". Then, your activity method onConfigurationChanged will be invoked and you can handle it however you want.

Probably you won't need any special handling since the layouts know how to relayout and draw themselves.

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
0

Try this:

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
 //Do your operation and agin unfix orientation
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
GrIsHu
  • 29,068
  • 10
  • 64
  • 102