Amit Raz
Amit Raz

Reputation: 5534

handeling orientation change in android

I wanted to have a differnet look to one of my activities when the orientation changes. I created the layout-land folder and added activity1.xml there but when I switch the orientation I still get the regular activity.

Is there anything else I need to do to make it work?

Thanks.

Upvotes: 0

Views: 862

Answers (2)

Peter Knego
Peter Knego

Reputation: 80340

Do you have android:configChanges attribute defined in your manifest?

There are two ways the orientation change can be handled:

  1. You define attribute android:configChanges="orientation" in your app's mainfest and implement onConfigurationChanged() in your activity. This method will then be called when orientation changes.

  2. You do NOT define android:configChanges attribute. The you activity will be restarted (a new activity crated) and will go through a lifecycle process (onCreate, onStart, etc), every time orientation of device changes.

Upvotes: 4

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43108

Read here about configuration changes. You can override onConfgiratationChanged() method of your activity and set a content view to the activity1 layout.

Upvotes: 0

Related Questions