I’m trying to port existing phonegap application (iOS/Android) to WP7. Everything works fine, except code for handling “back” button. Currently there is handler for back button, which does reloads page if logic asks for it, or closes application if user is in “first”page.
Code:
if (doLogic) {
// some update logic
} else {
// try to close app
device.exitApp();
}
Unfortunately, althought, update logic works, I’m unable to close app.
Seems that with current PhoneGap implementation it is impossible to add back button handler and still allow application to close with back button.
Solved this with little hacking into PhoneGap, by changing page_BackKeyPress method in CordovaView.xaml.cs
Changed if(OverrideBackButton) to
Now I can add shouldCancelBackButton JS function in page and based on state suppress or execute default back button handler behaviour.
Probably it’s not the best solution, but unfortunately I have no time for getting more familiar with PhoneGap internals.