Cordova Device and Application events -


i listen on events such application closing , device shut down run code (such logout feature) before application closes or device shut down / sleep events.

is possible cordova/phonegap? looked plugins , found plugins powermanagement related events nothing these events.

thanks

you're not able listen on events onappclose nor ondeviceshutdown or onexit - these events don't exist.

there events can triggered adding eventlistener code.

example

deviceready eventlistener

document.addeventlistener("deviceready", yourcallbackfunction, false); 

the yourcallbackfunction fire when device has entered deviceready state.

a documentation eventlisteners given cordova/phonegap can found here: cordova - eventlistener documentation


as bipbip said in his answer, there possibilty trigger such events onunload attribute inside body tag, tested inside clean cordova application.

<!doctype html> <html>     <head> <!--        <meta http-equiv="content-security-policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">--> <!--        <meta name="format-detection" content="telephone=no">--> <!--        <meta name="msapplication-tap-highlight" content="no">-->         <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">         <link rel="stylesheet" type="text/css" href="css/index.css">         <title>hello world</title>     </head>     <body onload="alert('onload fired');" onunload="alert('onunload fired');">         <script type="text/javascript" src="cordova.js"></script>     </body> </html> 

so onunload never fired (nor if replace alert console.log()) because cordova apps totaly closed never fire such events.

an alternative of behaviours onpause eventlistener. 1 fires instantly after user switches application or taps home button homescreen. 1 gets implemented by:

document.addeventlistener("pause", onpausefired, false); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -