PhoneGap & The Android Back Button (0.9.5)

In PhoneGap 0.9.5 they’ve updated how the Android back button works. Here’s what to change.

Before in 0.9.4:

document.addEventListener("backKeyDown", function() {
}, true);

Now in 0.9.5:

document.addEventListener("backbutton", function() {
}, true);

In 0.9.5 and later you no longer need to override the back button, as it’s assumed when you’re adding the event listener that you want to handle the button yourself. Make sure if the user is at the root view of your mobile app, the back button closes the app.

To exit the app in 0.9.4 you’d use:


Now, in 0.9.5 you need to use:


Good to see PhoneGap advancing to a more device agnostic syntax.

5 thoughts on “PhoneGap & The Android Back Button (0.9.5)

  1. device.exitApp() doesn’t work for me on my droid incredible. I’m not sure why. I’ve also tried navigator.device.exitApp();

    Neither exits the app.

  2. Hi!

    I tried this too…but it doesn’t work!
    i am using phonegap v1.0 and i tried; Backbutton.exitApp();

    Well the application “closes”. you get back to the homescreen. but the application is still running! one can see that if you go to the system preferences and look for information about the app. there you have to force the system to quit the app.

    afterwards the app will start smoothly again!

    have you any ideas!?


Comments are closed.