Skip to content

Commit

Permalink
apache#1002: Add Null Pointer Checks to prevent Cordova from running …
Browse files Browse the repository at this point in the history
…on a destroyed activity
  • Loading branch information
rick-habets-kbc-be committed Aug 12, 2020
1 parent f1f4722 commit 06222ad
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions framework/src/org/apache/cordova/CordovaWebViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,23 @@ public void run() {
}

// If timeout, then stop loading and handle error
if (loadUrlTimeout == currentLoadUrlTimeout) {
if (loadUrlTimeout == currentLoadUrlTimeout && cordova.getActivity() != null) {
cordova.getActivity().runOnUiThread(loadError);
}
}
};

final boolean _recreatePlugins = recreatePlugins;
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
if (loadUrlTimeoutValue > 0) {
cordova.getThreadPool().execute(timeoutCheck);
if (cordova.getActivity() != null) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
if (loadUrlTimeoutValue > 0) {
cordova.getThreadPool().execute(timeoutCheck);
}
engine.loadUrl(url, _recreatePlugins);
}
engine.loadUrl(url, _recreatePlugins);
}
});
});
}
}


Expand Down Expand Up @@ -238,7 +240,9 @@ public void showWebPage(String url, boolean openExternal, boolean clearHistory,
} else {
intent.setData(uri);
}
cordova.getActivity().startActivity(intent);
if (cordova.getActivity() != null) {
cordova.getActivity().startActivity(intent);
}
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
Expand Down Expand Up @@ -535,11 +539,13 @@ public void onPageFinishedLoading(String url) {
public void run() {
try {
Thread.sleep(2000);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
pluginManager.postMessage("spinner", "stop");
}
});
if (cordova.getActivity() != null) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
pluginManager.postMessage("spinner", "stop");
}
});
}
} catch (InterruptedException e) {
}
}
Expand Down

0 comments on commit 06222ad

Please sign in to comment.