PDA

View Full Version : Android browser autoreload breaks app



Ralph Haygood
19 Apr 2011, 9:39 PM
I've built an app using Sencha Touch 1.1.0, and it's having the following problem in the Android browser on a Nexus One running Android 2.3.3 (but I doubt the problem is specific to this phone or Android version). I load the app in a browser window, I leave it to do other things (visit other web pages, read email, etc.), and when I return to the app, the browser automatically reloads the window. So far, no surprise - web pages are held in RAM, of which the phone has a fairly limited supply, so my app eventually gets flushed; this behavior of the Android browser is well known (and much complained about, e.g., http://goo.gl/giNZp). The problem is that the app doesn't get reloaded properly. The result of the reload is an almost blank window; all that's visibly left of the app is its body background image. Worse yet, manually reloading the app now yields the same result, an almost blank window. The only way back to normal I've found is to manually stop the browser (via Settings -> Applications -> Manage applications -> All -> Browser -> Force stop) and relaunch it. I've never seen this almost-blank-screen syndrome except when there's an automatic reload; manual reloads by themselves don't elicit it, as far as I can tell.

I'm hoping someone else has had this problem and has some idea how to solve it. I'm not including any of my code in this post, because I have no idea which portion(s) of my code might be relevant. If anyone else has an idea and wants to see code, I'm happy to post it.

And, of course, if there's a relevant forum thread, please just refer me to it. I've searched but not found anything obviously relevant.

Ralph Haygood
29 Apr 2011, 4:40 AM
I see nobody has anything to say about this yet. On the outside chance I'm not just specially cursed, here are a couple of things I've discovered. First, my onReady handler, declared using Ext.setup, is simply not being called on these pathological reloads - hence the blank screen, because everything that should appear is programatically constructed pursuant to the handler. Second, I can "solve" the problem by merely putting an alert in the body, like

<body>
<script type="text/javascript">
alert("Huh?")
</script>
...
</body>

Of course, that's hardly a solution, and it even makes things harder, because I can't use alerts to follow what's going on - they make the problem disappear, in a fiendishly Heisenbergian fashion. And once the browser reloads the page correctly, it keeps doing things right on subsequent reloads, until the next autoreload. The only way back to the problematic state is to wait, as far as I know.

This is a serious contender for the most horrible bug I've ever seen.

What I've discovered suggests the problem is a subtle matter of timing. The logic of Sencha's onDocumentReady is murky to me, but I note that it involves calls to setTimeout and setInterval. I've tried increasing the times in these calls, but it doesn't seem to help.