views:

77

answers:

1

Hello. I have a very simple Activity...

public class ShowOrientation extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Log.d("ShowOrientation", "Orientation: " + getOrientation());
    }

    private String getOrientation() {
        int o = getResources().getConfiguration().orientation;
        if (o == 1)
            return "PORTRAIT";
        else if (o == 2)
            return "LANDSCAPE";
        else
            return "*UNKNOWN!*";
    }

}

When I run the Activity in the emulator, it starts up in PORTRAIT mode. When I rotate the screen (via the 9 button on the numeric keypad), I see in my log file a single entry...

Orientation: LANDSCAPE

Now, if I rotate the screen back to PORTRAIT mode (via the 7 button on the numeric keypad), here is what I am seeing in my log file...

Orientation: LANDSCAPE
Orientation: PORTRAIT

And then if I switch back to LANDSCAPE again, I see this...

Orientation: LANDSCAPE

Since this logging is done in onCreate(Bundle), I can only assume that my Activity is being destroyed/created twice when rotating from LANDSCAPE to PORTRAIT screen orientation, and only once when going from PORTRAIT to LANDSCAPE!

I'm still new to Android, so I may be missing something about the activity lifecycle, but it doesn't seem right to me that an Activity is created/destroyed twice when doing a screen rotation one way, but only once when doing a screen rotation another way.

Did I find a bug? Is it supposed to work this way? Or do I not know something about activity lifecycle that explains this?

EDIT: Forgot to mention, this is using Android 2.2 api, Eclipse 3.5.2, and Android SDK Rev. 7.

+1  A: 

This is a documented bug and duplicate question, chronicled here: http://stackoverflow.com/questions/2988072/problems-when-handling-orientation-changes

Josh
For what its worth, I searched before posting. Didn't see the duplicate post.
Adrian Romanelli
I believe you, this is a hard one to categorize. Hope you didn't waste too much time trying to figure it out.
Josh
Well, I actually hate duplicate posts too, so I spent ~ 15 minutes Googling, and searching through here, before giving up and posting. But I also double-checked the list of subjects that comes up as you're creating a post here too.
Adrian Romanelli
Forgot to mention, its amazing how old the bug ticket is, and that this is still not fixed.
Adrian Romanelli