Search code examples
cordovaphonegap

Phonegap/Cordova build onResume event not working


I'm using Phonegap Build to create an app and I'm simply loading a whole webpage in the webview.

The problem is that the onResume and onPause event is not firing if I load the webpage, if I don´t load the page then it is firing as it should.

I use this.

function onBodyLoad() {
    document.addEventListener('deviceready', onDeviceReady, false);
}

function onDeviceReady() {

    document.addEventListener("resume", onResume, false);
    document.addEventListener("pause", onPause, false);

    setTimeout(function () {    
        //if I don´t use this, then the events are working, 
        //but as soon as I load the page the events are not firing?
        document.location.href = "http://somepage.se/";

    }, 0);

}

So why is the event working if I don´t load the webpage?


SOLVED! My mistake, when I load with window.load then it replaces my hole page, so therefor it never fires the event since it is gone. So I have to use jQuery to load it in a div instead, then it loads the page inside the existing one, it is not replacing it.


Solution

  • I was trying to figure out the problem you have, and I can tell you that this is not the problem which you actually have.

    onPause event fires when the native platform puts the application into the background, typically when the user switches to another application.

    OnResume event fires when an application is retrieved from the background.

    For full docs, read here!