How to get OrientationEventListener.onOrientationChanged() to be called only when UI rotates [duplicate]

StackOverflow https://stackoverflow.com/questions/5810988

Question

Possible Duplicate:
How do I detect screen rotation

Hello,

All I want to do, is to detect a rotation change in my application. However, I think I found a bug in the Android system. If you read this:

http://developer.android.com/guide/practices/optimizing-for-3.0.html#Landscape

It say's that every time the device changes orientation, Activity.onDestroy() is called , and the Activity.onCreate() is called. So I figured I could just use the Display.getRotation() method to figure out my new orientation in the Activity.onCreate() method. However, I discovered that for some reason onCreate() (or even onResume()) is never called if you flip the device quickly by 180 degrees. I proved this using toast messages. My toast message in my Activity.onCreate() (or in Activity.onResume()) would appear with 90 degree turns, but not with 180 degree flips of the device. So the point is, the claim in the article above isn't always true.

So then I decided to use OrientationEventListener.onOrientationChanged(). This works, but I don't want onOrientationChanged() to be called over and over in my app (it gets called with every single change of degree of the device). This will slow down everything else I'm doing. I only want it to be called when I rotate the screen enough to get the image on the screen to rotate so that I can figure out if I'm at rotation_0,rotation_90,rotation_180, or rotation_270.

This is with a xoom of course.

Any suggestions

Was it helpful?

Solution

Answered in detail here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top