Last Updated: February 25, 2016
·
3.785K
· shupal

Prevent timeouts in phonegap on android emulator

First way to avoid a timeout on application start up is to increase the TimeoutValue before the index.html is loaded.

super.setIntegerProperty("loadUrlTimeoutValue", 70000);
super.loadUrl("file:///android_asset/www/index.html");

But sometimes it doesn't work (or just in my case). A alternate way is to create a new html file called helper.html or something else.

<!-- helper.html -->
<!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <script>
                window.location='./index.html';
            </script>
        <body>      
        </body>
    </html>

After the file is loaded we say that our new window.location is our normal index.html.
Just change the line in your MainActivity class

super.loadUrl("file:///android_asset/www/index.html");

to

super.loadUrl("file:///android_asset/www/helper.html");

and your app is not running into a timeout on the emulator.

2 Responses
Add your response

Hello,
This is the case where the index.html file times out. I have an issue where I am trying to embed a youtube url inside a popup in my app. When internet is not present or it is slow enough, it gives an alert saying : "Couldn't load url: http://www.youtube.com/embed/...." . When I click on the OK button, the app crashes.
I tried increasing the super.setIntegerProperty("loadUrlTimeoutValue",60000) value inside Phonegapactivity.java file, but it doesn't seem affecting the youtube url as it crashes before the timeout.

Any pointers on this would be greatly appreciated.Thanks.

over 1 year ago ·

The video is embed? Via inAppBrowser Plugin?

over 1 year ago ·