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
string cancel = "false";
if (OverrideBackButton)
{
try
{
cancel = CordovaBrowser.InvokeScript("shouldCancelBackButton") as string;
Console.WriteLine("CancelBackButton response: " + cancel);
}
catch (Exception ex)
{
Console.WriteLine("Exception while checking for backbutton cancel into cordova view: " + ex.Message);
}
try
{
e.Cancel = cancel == "true";
CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" });
}
catch (Exception ex)
{
Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message);
}
}
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.