PhoneGap quit Android Program

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.