Frequently PhoneGap applications consist of multiple screens represented by divs. Since Android users are conditioned to push the back button to return to the previous screen this causes some confusion as the default behaviour is to close the app. Luckily PhoneGap provides developers a way to over ride the default back button behaviour so they may provide their own back behaviour.
In release 0.9.4 the developer would have to wait for the deviceready event and call:
document.addEventListener("backKeyDown", backPressed, false);
In order to setup and event handler for the back key and:
to revert to the default behaviour.
As of PhoneGap 0.9.5 we've made overriding the back button behaviour easier. You still have to wait for the deviceready event but the calls have been simplified to:
document.addEventListener("backbutton", onBackKey, false);
to register your event handler for the back key and:
document.removeEventListener("backbutton", onBackKey, false);
to revert to the default Android back button behaviour.
The following listing shows a full, yet contrived, example: