2

I have a simple android app, built for API level 7. The only uncommon thing is that it has android:screenOrientation="portrait" in its manifest. Also in its manifest the API levels are specified as android:targetSdkVersion="11" android:minSdkVersion="7".

It works as expected on an AVD with API level 8, but when run in an AVD with API level 11 I found out that its main activity's onCreate() was run twice at startup. The only thing that came to my mind was that a configuration change occurred, so I put the following line:

android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale"

into the manifest an also the lines:

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

into the main activity and put a breakpoint on the super... line. When I debug (using Eclipse/ADT), it breaks on that line.

I don't know how to find out what in the configuration has changed.

In the AVD on API level 11, the screen is in landscape mode before the app is started, but when the app is running, it is in portrait mode, I guess, as it has its top to the left.

In the AVD on API level 8, the main activity does not run into this breakpoint and onCreate() is only called once.

Now, if I change to android:screenOrientation="landscape", neither of the two AVD's causes a break due to a configuration change, and thus onCreate() is only run once. It would at least have been similarity in the behaviour on the two AVD's if the AVD on API level 8 would have run into the breakpoint with this setting.

Have anyone seen this, which I think, odd behaviour of an AVD with API level 11 and perhaps have a clue?

I also discovered that another activity of this simple app, used for setting preferences, shows up i landscape mode, and when returning from the preferences screen/activity to the main activity, the main activity starts over with onCreate(), so it seems that the main activity is struck by another configuration change. When I specified the preferences activity to also be in portrait mode in the manifest, that second problem dissappeared.

Jan

RzR
  • 3,068
  • 29
  • 26

0 Answers0