Stop Exit on Back Button Android in PhoneGap - Build

后端 未结 2 1812
一向
一向 2020-12-17 03:19

I\'m building my application through PhoneGap Build online. I want to change the default behavior of Back Button

$(document).ready(function(         


        
2条回答
  •  猫巷女王i
    2020-12-17 03:51

    First of all I did wrong as pointed by @Mejo, Thanks. Here is the solution to the problem.

    Step 1: Include Script to HTML don't need it physically within application zip, as included automatically by PhoneGap Build

    or any of them will work fine.

    Step 2: Add this to script to get device ready call:

    document.addEventListener("deviceready", onDeviceReady, false);
    

    Step 3: Add event listener to back button and add your code to that call:

    function onDeviceReady(){
        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    function onBackKeyDown(){
        alert('back');
        return false;
    }
    

    Still now it will not work if you don't set preference of minSDK to application by config.xml

    Step 4: Add this to preference region of config.xml

    For reference: http://community.phonegap.com/nitobi/topics/how_to_handle_back_button_in_android

提交回复
热议问题