0

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.

user1763170
  • 119
  • 1
  • 2
  • 13
  • Are you missing the @Override annotation before `public void onConfigurationChanged` – petey Oct 22 '12 at 17:39
  • @forgivegod `@Override` doesn't effect if it works or not. it's just a reminder and is good practice. – Flynn Oct 22 '12 at 17:41
  • 1
    @Override doesn't do anything other than help you avoid typos. From the code you've posted I think it should work, you'll probably have to post more complete code to get a decent answer (and a proper minimal example rather than a huge dump). Sorry! – Timmmm Oct 22 '12 at 17:42
  • 1
    You probably need to add screenSize to `android:configChagnes="orientation|screenSize"`, if you are targeting API level 13 and higher. Here is the source: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange – Wenhui Oct 22 '12 at 17:55
  • Thanks everyone. Targeting API 10. Haven't solved it yet. – user1763170 Oct 22 '12 at 19:03
  • I'm using an application class would this make a difference as to how this is managed? – user1763170 Oct 22 '12 at 19:39

2 Answers2

2

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

Community
  • 1
  • 1
Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
0

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.

Community
  • 1
  • 1
Diana
  • 2,186
  • 1
  • 20
  • 31