Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orientation Changed Event or Listener Android

Is there any event or listener which fires @ time of orientation changed?

or, how to find out that the orientation of phone is changed?

Thank You

like image 425
Nixit Patel Avatar asked Dec 12 '11 14:12

Nixit Patel


People also ask

What happens when screen orientation changes in Android?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.

Which method called when orientation changes android?

First onPause(), onStop() and onDestroy() will be called simultaneously and after some time when the activity restarts the onCreate(), onStart() and onReume() methods will be called simultaneously. So when you change the orientation of a screen the Activity will be restarted.

How do I stop Android from restarting activity when changing orientations?

If you want the activity to not restart during screen orientation change, you can use the below AndroidManifest. xml. Please note the activity android:configChanges=”orientation|screenSize” attribute. This attribute makes the activity not restart when change screen orientation.

How do I change the orientation of an Android app?

On the main screen of Rotation Manager, select an orientation by tapping on either the vertical or horizontal icons next to a specific app to lock it into either landscape or portrait mode. Highlighting both icons will allow that particular app to auto-rotate.


4 Answers

You need to read up on Handling Runtime Changes.

It explains the old way of doing handling stuff like orientation change.

Since Fragments was introduced, they have implemented a new way of doing it (similar to the old one) - but if you don't use Fragments it makes no sense using it.

like image 95
kaspermoerch Avatar answered Oct 24 '22 06:10

kaspermoerch


As far as I know there is a listener for this,

Check out http://developer.android.com/reference/android/view/OrientationListener.html

That is the class have a look through there.

Hope that helped.

like image 36
Phil Kearney Avatar answered Oct 24 '22 06:10

Phil Kearney


You can use OrientationEventListener class instead !! http://developer.android.com/reference/android/view/OrientationEventListener.html

like image 34
amd Avatar answered Oct 24 '22 05:10

amd


If you are more interested in when an orientation change triggers a redisplay of the layout, you might want to check out this: http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html

"Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing."

like image 40
Norman H Avatar answered Oct 24 '22 05:10

Norman H