last day (14 days later) » 

12:30 PM
-1
Q: When i press Backbutton doesn't work on phonegap(Android)?

Kishore KumarAt first time this code working fine ,but when i move to some other screen and came back to this screen back button not working. <script> function onLoad() { alert("device ready"); document.addEventListener("deviceready", onDeviceReady, false); } functio...

 
@JesperHøjer i didn't checked with that ,i just run using phonegap app
@Vikram this is for android platform
@JesperHøjer ok sure i will try
 
@KishoreKumar you gotta note few things here. First, once you navigate to next page, ensure to remove backbutton listener. Then in backbutton listener button ensure to add preventdefault. The below code works for me in my app:
@KishoreKumar function onDeviceReady() { document.addEventListener("backbutton", onBackButton, false); } function onBackButton(e) { e.preventDefault(); navigator.notification.confirm("Are you sure you want to exit ?", onConfirm, "Confirmation", "Yes,No"); } function onConfirm(button) { if (button == 2) { return; } else { navigator.app.exitApp(); } }
@KishoreKumar To remove listener use, document.removeEventListener("backbutton", onBackButton, false);
 
@Gandhi bro on home screen when user press back button always i want to exit my app but above code works on first time when i moves to some screen its doesn't work y ?
 
@KishoreKumar It should exit from other screens as well?
 
@Gandhi bro i updated my question pls check it.
 
12:30 PM
@KishoreKumar Ensure to add the code you posted inside body onload or document ready function so that it get initiailzed on load of homescreen everytime. Also its better to remove the listener once you move away fron home screen to subsequent screens
 
@Gandhi bro updated my code
 
its body onload not onLoad
try out the code is sent it works fine in my case
 
back button works but navigator.app.exitApp not working
 
whats the error?
 
no error bro
 
12:45 PM
have u installed dialog plugin?
 
no bro whats that ?
 
1:05 PM
CORDOVA PLUGIN
 
what is the use of that plugin bro
 
i guess its required for navigator.app.exitApp
 
ok bro i will check it
 
PLZ GET BACK IF IT WAS USEFUL
 
1:42 PM
@Gandhi not working bro
 
2:20 PM
you gotta test it in device
 

last day (14 days later) »