Reputation: 14875
Following is simple html, when viewed on android browser(nexus one) results into continuos orientationchange event chain when you change phone's orientation just once.
<html><body>
<script type="text/javascript">
window.addEventListener("orientationchange",function(){alert("test");},false);
</script>
</body></html>
Can somebody please explain and suggest some workaround?
Upvotes: 3
Views: 5017
Reputation: 1
These devices seem to trigger an 'orientationchange' event before the window is resized to reflect the new orientation.
How to fixed this: github
Upvotes: 0
Reputation: 57474
orientationchange is fired spuriously: opening an alert dialog, or opening the browser menu fires it, and it often fires more than once. So, opening the alert menu causes an event loop, which means that the browser has to be killed manually--it lacks even basic protection against alert loops and it renders the menu inaccessible.
(I don't understand any production browser that can be taken out by while(1) alert("");
. Since when is remote JavaScript code trusted? It's the most obvious client-DoS, and happens inadvertently all the time, yet many major browsers are oblivious to it. Opera is the only browser I know that handles it correctly, making alerts modal to the viewport and not the browser itself.)
Upvotes: 4
Reputation: 2946
I think Falmarri means that by default that is what happens. You can prevent it from happening and listen for configuration changes in your activity, and then rotate the screen yourself, then the activity isn't restarted. See this series on rotation.
Upvotes: 0