R4chi7 R4chi7 - 1 month ago 6
Android Question

why is onCreate() being called after onConfigurationChanged?

I have created an activity and two layouts for the activity, one each for landscape and portrait mode. Both the layouts have same Views and IDs. In the manifest file, I have added

in the activity.

Now, according to the documentation, the activity is not restarted if I mention configChanges and include the

onCreate(Bundle savedInstanceState) {
Log.i("Message","inside oncreate()") ;

onConfigurationChanged(Configuration newConfig) {
Log.i("Message","inside onconfigurationchanged()") ;

My log is showing both messages when i change the orientation. Is there any way to stop the onCreate() method from being called when the orientation changes?

Thanks in advance.


maybe you could add more configurations changes that you wish to ignore, since starting of a certain API on android, the orientation consist of other flags , as the documentation says about "orientation" :

The screen orientation has changed — the user has rotated the device. Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

so, please try to use , and tell us if it helped :


here's the documentation about "screenSize":

The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). Added in API level 13.

EDIT: here's my simple code to show that it works:

public class MainActivity extends Activity {

    protected void onCreate(final Bundle savedInstanceState) {
        Log.i("Message","inside oncreate()");

    public void onConfigurationChanged(final Configuration newConfig) {
        Log.i("Message","inside onconfigurationchanged()");


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.test" android:versionCode="1"

  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />

  <application android:allowBackup="true" android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" android:theme="@style/AppTheme">
    <activity android:name="com.example.test.MainActivity"
      android:label="@string/app_name" android:configChanges="orientation|screenSize">
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />