0

In my application, I need to be informed when the orientation of the android device changes. I found two approaches to do that:

  1. Listen to onConfigurationChanged - Using this approach, I get the event when the phone changes from portrait to landscape and vice versa, but I do not get an event when the device changes from 90 degrees to 270 degrees - since in both the cases the orientation is still landscape.

  2. Listen to onOrientationChanged (OrientationEventListener) - This event is getting fired too many times. I just need to know when the device changes between 0, 90, 180 and 270 degrees. I tried using various values for "rate".

Is there third way to achieve what I want? I can share the code if required.

Gan
  • 1,349
  • 2
  • 10
  • 27
Bonton255
  • 2,231
  • 3
  • 28
  • 44

3 Answers3

0
 if(c.orientation == Configuration.ORIENTATION_PORTRAIT ) 

use this configuration class and get the run time device orientation

Zala Janaksinh
  • 2,929
  • 5
  • 32
  • 58
  • as i already mentioned, i dont get a configuration changed event when i move from 90 to 270 degrees. How does your solution solve that problem? – Bonton255 Sep 19 '12 at 17:07
  • Just mention it this code working in change the proper orientation then detect the effect ok.. – Zala Janaksinh Sep 20 '12 at 04:33
0

I finally fixed this by handling the events from OrientationEventListener. It fires too many times for comfort but it serves the purpose.

Bonton255
  • 2,231
  • 3
  • 28
  • 44
0

if the client insists on testing on old android:

<script>
    window.addEventListener("orientationchange", function() {
        location.reload();
    }, false);
</script>

wakawakawaka

jake
  • 1