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
<script src="cordova.js"></script>
or <script src="phonegap.js"></script>
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
<preference name="android-minSdkVersion" value="5" />
For reference: http://community.phonegap.com/nitobi/topics/how_to_handle_back_button_in_android
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…