forked from github/cordova-android
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
This commit is contained in:
parent
892f96e305
commit
cb192056f8
@ -755,7 +755,9 @@ public class CordovaWebView extends WebView {
|
|||||||
// If not, then invoke default behaviour
|
// If not, then invoke default behaviour
|
||||||
else {
|
else {
|
||||||
//this.activityState = ACTIVITY_EXITING;
|
//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()
|
public void handleDestroy()
|
||||||
{
|
{
|
||||||
// Send destroy event to JavaScript
|
// 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
|
// Load blank page so that JavaScript onunload is called
|
||||||
this.loadUrl("about:blank");
|
this.loadUrl("about:blank");
|
||||||
@ -916,11 +919,14 @@ public class CordovaWebView extends WebView {
|
|||||||
{
|
{
|
||||||
WebBackForwardList currentList = this.copyBackForwardList();
|
WebBackForwardList currentList = this.copyBackForwardList();
|
||||||
WebHistoryItem item = currentList.getItemAtIndex(0);
|
WebHistoryItem item = currentList.getItemAtIndex(0);
|
||||||
String url = item.getUrl();
|
if( item!=null){ // Null-fence in case they haven't called loadUrl yet (CB-2458)
|
||||||
String currentUrl = this.getUrl();
|
String url = item.getUrl();
|
||||||
LOG.d(TAG, "The current URL is: " + currentUrl);
|
String currentUrl = this.getUrl();
|
||||||
LOG.d(TAG, "The URL at item 0 is:" + url);
|
LOG.d(TAG, "The current URL is: " + currentUrl);
|
||||||
return currentUrl.equals(url);
|
LOG.d(TAG, "The URL at item 0 is:" + url);
|
||||||
|
return currentUrl.equals(url);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
|
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
|
||||||
|
Loading…
Reference in New Issue
Block a user