I am trying to create an app with different background images when in portrait vs landscape mode on a fullscreen activity, but, it always uses the background image from the portrait layout for both.

Does anybody know why this happens?


After a lot of googling and combining results from different locations, I found an answer that works for me.

First of all, if the AndroidManifest.xml file contains


Then it means that your activity config won't refresh when orientation changes, and you are given the opportunity to handle it manually via onLayoutChange, which I chose to do as follows:

// Use a layout change listener to re-apply the background image if
// orientation changes.

   fScreenView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                                   int oldTop, int oldRight, int oldBottom) {
            int orientation = getResources().getConfiguration().orientation;
            if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
                fScreenView.setBackgroundResource (R.drawable.sab_logo_text_2);
            } else {
                fScreenView.setBackgroundResource (R.drawable.sab_logo_text_1);

If that does not float your boat, you can always just let Android handle it for you by killing and restarting your activity in the correct layout (in my case, correct orientation) by simply removing


from the manifest file. In my case, the actual default value was


and needs to be changed to


After which the activity will be killed and restarted in the correct layout. On my application, the in-code method proved to be faster, so I handled it in code.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.