1

So i have simple code, i just want to change layout when i screen orientation is changed.

package com.example.asdasd;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

    public void onConfigurationChange(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.asdasd);
    System.out.println("orientation---"+getResources().getConfiguration().orientation);
}

}

my manifest is

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

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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

So when i try this out on emulator and use ctrl+f12 or 9and 7 on num, screen flips but nothing happends and my layout stays the same, it wont work. Its like onConfigurationChange is never called and System.out.println is never reached.

Pitonchina
  • 11
  • 2
  • you may want to tag this with something that will attract the attention of android experts – dav1dsm1th Nov 15 '13 at 20:14
  • I got similar problem. My app uses android:configChanges="locale" in the Manifest file. The onConfigurationChanged() is never called when I switch to settings to change the mobile device locale and switch back to the activity. The logcat messages show that the activity just onCreate, onResume, ... etc and never go to onConfigurationChanged. – Alvin SIU Jan 26 '14 at 04:16

0 Answers0