user1763170
user1763170

Reputation: 117

onConfigurationChanged not getting called on rotation

my problem is onConfigurationChanged is not getting called.

Code is as follows:

    public void onConfigurationChanged(Configuration newConfig) {
    Log.i("onconfig", "#### CALLED!"); 
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
        LinearLayout listContainer = (LinearLayout)findViewById(R.id.list_container);

        if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
            listContainer.setOrientation(LinearLayout.HORIZONTAL);
        }
        else{
            listContainer.setOrientation(LinearLayout.VERTICAL);
        }
//      end if else
        }
// end of on configuration changed

In the manifest I have:

<activity
        android:name=".FirstListActivity"
        android:label="@string/title_activity_fruits_list"
            android:configChanges="orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Thanks to anyone who can help.

Upvotes: 0

Views: 2031

Answers (2)

Diana
Diana

Reputation: 2226

See this answer: https://stackoverflow.com/a/6109206/1182515

Do you use this method in your onCreate?

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

When using that you will not receive orientation changes.

Try the solutions given in the linked post.

Upvotes: 0

Rupesh Yadav
Rupesh Yadav

Reputation: 12302

Add screenSize value as well in android:configChanges attribute tag. for more read this answer

Upvotes: 2

Related Questions