Hello, i want to ask you a qustion about the back button on android devices. I make an app with many pages and when I click this button the app return the last page. I want to exit the app when the back button is clicked. Please support.
Hello, i want to ask you a qustion about the back button on android devices. I make an app with many pages and when I click this button the app return the last page. I want to exit the app when the back button is clicked. Please support.
Hello,
We have PhoneGap "Back button" event.
You can add to this event Run JavaScript Action with following JavaScript code:
codenavigator.app.exitApp();/codeYou'll exit the app on "Back" button click.
Each screen has this event. If you want it to work everywhere add this action to all the screns.
Or you can create JavaScript asset:
codedocument.addEventListener("backbutton", function( e )
{
navigator.app.exitApp();
}, false);/codeThis will work globally on each screen.
I created new JavaScript and pasted the code. After that i copied the apk file to my phone and it ran correctly but when i press the back button(I am with Galaxy Nexus Android 4.2) the app returns back screen but it does not exit. What I should do?
Add an alert to make sure the event is fired.
How to add an alert?
You can add following JavaScript:codealert("Alert!");/code
alert("document.addEventListener("backbutton", function( e )
{
navigator.app.exitApp();
}, false);")
Or you can create JavaScript asset:
document.addEventListener("backbutton", function( e )
{
navigator.app.exitApp();
}, false);
This will work globally on each screen.
Where and how to do that? Sorry I am new and I need a little help ![]()
Go to Create New - JavaScript.
Then enter JavaScript file name in appeared window.
JavaScript editor will be opened. Paste the code there.