cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject android commit: CB-2458: gracefully exit with back button If users do extra initialization, we can get NPEs when hitting the back button before loadUrl() has been called. -Null fenced code in startOfHistory() that gave us an NPE when hitting Back button
Date Tue, 19 Feb 2013 16:56:45 GMT
Updated Branches:
  refs/heads/master 892f96e30 -> cb192056f


CB-2458: gracefully exit with back button
If users do extra initialization, we can get NPEs when hitting the back
button before loadUrl() has been called.
-Null fenced code in startOfHistory() that gave us an NPE when hitting
Back button with useBrowserHistory=true
-Call finish() in Back button code when no history since with
useBrowserHistory=true it would just hang while the app inits
-Call loadUrlIntoView() first in handleDestory() since with
useBrowserHistory=false, the default behavior would try to use the baseUrl
which is null


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/cb192056
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/cb192056
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/cb192056

Branch: refs/heads/master
Commit: cb192056f82e051a05bbda8b09ac01a118c39838
Parents: 892f96e
Author: mbillau <mike.billau@gmail.com>
Authored: Mon Feb 18 16:42:14 2013 -0500
Committer: mbillau <mike.billau@gmail.com>
Committed: Mon Feb 18 16:42:14 2013 -0500

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   20 +++++++++-----
 1 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/cb192056/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index 7d653c3..4731adb 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -755,7 +755,9 @@ public class CordovaWebView extends WebView {
                     // If not, then invoke default behaviour
                     else {
                         //this.activityState = ACTIVITY_EXITING;
-                        return false;
+                    	//return false;
+                    	// If they hit back button when app is initializing, app should exit
instead of hang until initilazation (CB2-458)
+                    	this.cordova.getActivity().finish();
                     }
                 }
             }
@@ -853,7 +855,8 @@ public class CordovaWebView extends WebView {
     public void handleDestroy()
     {
         // Send destroy event to JavaScript
-        this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception
firing destroy event from native');};");
+    	// Since baseUrl is set in loadUrlIntoView, if user hit Back button before loadUrl was
called, we'll get an NPE on baseUrl (CB-2458)
+        this.loadUrlIntoView("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception
firing destroy event from native');};");
 
         // Load blank page so that JavaScript onunload is called
         this.loadUrl("about:blank");
@@ -916,11 +919,14 @@ public class CordovaWebView extends WebView {
     {
         WebBackForwardList currentList = this.copyBackForwardList();
         WebHistoryItem item = currentList.getItemAtIndex(0);
-        String url = item.getUrl();
-        String currentUrl = this.getUrl();
-        LOG.d(TAG, "The current URL is: " + currentUrl);
-        LOG.d(TAG, "The URL at item 0 is:" + url);
-        return currentUrl.equals(url);
+        if( item!=null){	// Null-fence in case they haven't called loadUrl yet (CB-2458)
+	        String url = item.getUrl();
+	        String currentUrl = this.getUrl();
+	        LOG.d(TAG, "The current URL is: " + currentUrl);
+	        LOG.d(TAG, "The URL at item 0 is:" + url);
+	        return currentUrl.equals(url);
+        }
+        return false;
     }
 
     public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {


Mime
View raw message