Recently, using Android to do a program, in the "back" of the point, will keep back, feel bad.
We've got some information:
First, Toast_plugin plug-in
<script type="Text/javascript"charset="Utf-8"Src="Cordova-2.0.0.js"></script> <script src="Toast_plugin.js"></script>document.addeventlistener ("Deviceready", Ondeviceready,false); function Ondeviceready () {
Document.addeventlistener ("Backbutton", Eventbackbutton,false);//Return key}
function Eventbackbutton () {Window.plugins.toastPlugin.show_long ('One more click to exit!'); Document.removeeventlistener ("Backbutton", Eventbackbutton,false);//Logout Return key//re-register after 3 seconds varIntervalid =Window.setinterval (function () {window.clearinterval (intervalid); Document.addeventlistener ("Backbutton", Eventbackbutton,false);//Return key},3);
This is the implementation of many apps now double-click the return key to exit the program function;
Second, press the return key, bounce exit confirmation box
Document.addeventlistener ("Deviceready", Ondeviceready,false);
function Ondeviceready () {Document.addeventlistener ("Backbutton", Eventbackbutton,false);// monitor Events//
}//event handling
function Eventbackbutton () {showconfirm ();}//Confirm API provided by PhoneGap Notificationfunction showconfirm () {navigator.notification.confirm (' PressMake sure to exit',//messageOnconfirm,//callback function ' whether to exit',//title ' OK, Cancel' //confirm option, separate with the number );}
function onconfirm (button) {
if (Button = = = 1) {
NAVIGATOR.APP.EXITAPP ();
}
}
The above 2 basically can meet the requirements, but still feel what is wrong.
Sometimes you want to return to the back effect, and the result is programmed to exit the program.
This time to add a judgment, the following code combined with the above method can be solved perfectly!
Document.addeventlistener ("backbutton", Onbackkeydown,false
function Onbackkeydown () { if($.mobile.activepage. is ('#homepage'))
NAVIGATOR.APP.EXITAPP ();
Else
Navigator.app.backHistory ();