Phonegap (Cordova) - Back button triggers pause event instead of backbutton event in Android -
using cordova-2.7.0 android have following js script.
while testing back-button functionality, faced weird behavior.
at first run of application, when press back-button 'backbutton' event triggered , 'onbackbutton' function called.
when exit application , run application again, 'onpausebutton' function called instead of 'onbackbutton' function after pressing back-button.
after detailed study, realized 'navigator.app.exitapp();' (which cordova function) not destroy android application totally.
if delete application recent apps list , run again, 'backbutton' event triggered , 'onbackbutton' function called when press back-button.
so, want catch 'backbutton' event in each run of application.
what suggest me do?
thanks, v.h.
initialize: function() { document.addeventlistener('deviceready', this.ondeviceready, false); document.addeventlistener('backbutton', this.onbackbutton, true); document.addeventlistener('pause', this.onpausebutton, true); }, ondeviceready: function() { console.log("ondeviceready called"); }, onpausebutton: function() { console.log("onpausebutton called"); }, onbackbutton: function() { console.log("onbackbutton called"); console.log("current view: "+guimanager.currentview); if(guimanager.view_locale == guimanager.currentview ){ guimanager.showmatchlistscreen(); } else if(guimanager.view_matchlist == guimanager.currentview){ navigator.app.exitapp(); } }
i not know if solve issue. according code, possible try call cordova methods whereas cordova has not been loaded yet.
initialize: function() { document.addeventlistener('deviceready', this.ondeviceready, false); }, ondeviceready: function() { console.log("ondeviceready called"); document.addeventlistener('backbutton', this.onbackbutton, true); document.addeventlistener('pause', this.onpausebutton, true); }, onpausebutton: function() { console.log("onpausebutton called"); }, onbackbutton: function() { console.log("onbackbutton called"); console.log("current view: "+guimanager.currentview); if(guimanager.view_locale == guimanager.currentview ){ guimanager.showmatchlistscreen(); } else if(guimanager.view_matchlist == guimanager.currentview){ navigator.app.exitapp(); } }
please see phonegap doc link events: http://docs.phonegap.com/en/2.7.0/cordova_events_events.md.html#events
Comments
Post a Comment