1

I am building an app with Android 2.3.3 API. I need to recognize the change in orientation and perform some action. So I added the following in Android Manifest,

android:configChanges="orientation|keyboardHidden

And I override the method

public void onConfigurationChanged(Configuration newConfig)

It works perfect on Android 2.3.3. But when I install the same app (built with 2.3.3 API) on a 4.1.2, onConfigurationChanged() is not invoked. I searched online for solution and people suggest to add the following in android manifest.

 android:configChanges="orientation|keyboardHidden|screenSize"

If I build the app with above statement and built with 4.1.2 API, It works perfect on 4.1.2 device. But I cannot install it on 2.3.3. 2.3.3 API doesn't have "screenSize" option. So to support both, what should I do?

Thanks, Karthik

Karthik Andhamil
  • 848
  • 1
  • 13
  • 22
  • Possible duplicates http://stackoverflow.com/questions/6457659/android-onconfigurationchanged-not-being-called & http://stackoverflow.com/questions/5620033/onconfigurationchanged-not-getting-called – oldergod Dec 27 '12 at 05:53
  • Those does not help to my situation. As I said, they suggest me to add "screenSize". But it is not supported in 2.3.3 API. – Karthik Andhamil Dec 27 '12 at 06:00

4 Answers4

2

Hi Look at mine AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" 
    android:maxSdkVersion="16"/>

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

    </activity>
</application>

Bhavdip Sagar
  • 1,951
  • 15
  • 27
1

Just because you compile against, or target, a given API level does not mean you cannot explicitly support lower API levels. Try adding something like the following to your manifest. I took the levels from the versions mentioned in your question.

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="16"/>
iagreen
  • 31,470
  • 8
  • 76
  • 90
1

FYI Look Below code that i did used :

    @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
        Toast.makeText(getBaseContext(),"On Config Change LANDSCAPE", Toast.LENGTH_LONG).show();
    }else{
        Toast.makeText(getBaseContext(),"On Config Change PORTRAIT", Toast.LENGTH_LONG).show();
    }
}
Bhavdip Sagar
  • 1,951
  • 15
  • 27
0

Please note this point in your case : config changes 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.

Thank you

Bhavdip Sagar
  • 1,951
  • 15
  • 27