Hello. I have a very simple Activity...
public class ShowOrientation extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("ShowOrientation", "Orientation: " + getOrientation());
}
private String getOrientation() {
int o = getResources().getConfiguration().orientation;
if (o == 1)
return "PORTRAIT";
else if (o == 2)
return "LANDSCAPE";
else
return "*UNKNOWN!*";
}
}
When I run the Activity in the emulator, it starts up in PORTRAIT mode. When I rotate the screen (via the 9 button on the numeric keypad), I see in my log file a single entry...
Orientation: LANDSCAPE
Now, if I rotate the screen back to PORTRAIT mode (via the 7 button on the numeric keypad), here is what I am seeing in my log file...
Orientation: LANDSCAPE
Orientation: PORTRAIT
And then if I switch back to LANDSCAPE again, I see this...
Orientation: LANDSCAPE
Since this logging is done in onCreate(Bundle), I can only assume that my Activity is being destroyed/created twice when rotating from LANDSCAPE to PORTRAIT screen orientation, and only once when going from PORTRAIT to LANDSCAPE!
I'm still new to Android, so I may be missing something about the activity lifecycle, but it doesn't seem right to me that an Activity is created/destroyed twice when doing a screen rotation one way, but only once when doing a screen rotation another way.
Did I find a bug? Is it supposed to work this way? Or do I not know something about activity lifecycle that explains this?
EDIT: Forgot to mention, this is using Android 2.2 api, Eclipse 3.5.2, and Android SDK Rev. 7.