From 2a866e2a7ce11c33f3cf8381899939176f82b6bf Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Wed, 9 Nov 2011 23:37:16 -0600 Subject: [PATCH] Refactor backHistory() code so calling navigator.app.backHistory() has consistent behavior with backbutton. --- framework/src/com/phonegap/DroidGap.java | 31 +++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 35c1700a..b639dd66 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -577,13 +577,27 @@ public class DroidGap extends PhonegapActivity { /** * Go to previous page in history. (We manage our own history) + * + * @return true if we went back, false if we are already at top */ - public void backHistory() { - if (this.urls.size() > 1) { - this.urls.pop(); // Pop current url - String url = this.urls.pop(); // Pop prev url that we want to load - this.loadUrl(url); + public boolean backHistory() { + + // Check webview first to see if there is a history + // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior) + if (this.appView.canGoBack()) { + this.appView.goBack(); + return true; } + + // If our managed history has prev url + if (this.urls.size() > 1) { + this.urls.pop(); // Pop current url + String url = this.urls.pop(); // Pop prev url that we want to load, since it will be added back by loadUrl() + this.loadUrl(url); + return true; + } + + return false; } @Override @@ -1466,12 +1480,7 @@ public class DroidGap extends PhonegapActivity { else { // Go to previous page in webview if it is possible to go back - if (this.appView.canGoBack()) { - this.appView.goBack(); // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior) - return true; - } - else if (this.urls.size() > 1) { - this.backHistory(); + if (this.backHistory()) { return true; }