This is an automated email from the ASF dual-hosted git repository.
normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new 19a5feb fix: add not null checks to prevent running on destroyed
activity (#1148)
19a5feb is described below
commit 19a5feb87504e4fc8d6e17f82249acab06a1b74b
Author: Rick Habets <[email protected]>
AuthorDate: Sat Mar 27 16:19:46 2021 +0100
fix: add not null checks to prevent running on destroyed activity (#1148)
* (android) #1002: Add Null Pointer Checks to prevent Cordova from running
on a destroyed activity
* (android) Add logging statements if Cordova Activity does not exist
anymore (i.e. is destroyed)
Co-authored-by: Habets Rick <[email protected]>
---
.../src/org/apache/cordova/CordovaWebViewImpl.java | 46 ++++++++++++++--------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index a77502d..8fa313a 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -176,22 +176,28 @@ public class CordovaWebViewImpl implements CordovaWebView
{
e.printStackTrace();
}
- // If timeout, then stop loading and handle error
- if (loadUrlTimeout == currentLoadUrlTimeout) {
+ // If timeout, then stop loading and handle error (if activity
still exists)
+ if (loadUrlTimeout == currentLoadUrlTimeout &&
cordova.getActivity() != null) {
cordova.getActivity().runOnUiThread(loadError);
+ } else if (cordova.getActivity() == null) {
+ LOG.d(TAG, "Cordova activity does not exist.");
}
}
};
- final boolean _recreatePlugins = recreatePlugins;
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- if (loadUrlTimeoutValue > 0) {
- cordova.getThreadPool().execute(timeoutCheck);
+ if (cordova.getActivity() != null) {
+ final boolean _recreatePlugins = recreatePlugins;
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ if (loadUrlTimeoutValue > 0) {
+ cordova.getThreadPool().execute(timeoutCheck);
+ }
+ engine.loadUrl(url, _recreatePlugins);
}
- engine.loadUrl(url, _recreatePlugins);
- }
- });
+ });
+ } else {
+ LOG.d(TAG, "Cordova activity does not exist.");
+ }
}
@@ -238,7 +244,11 @@ public class CordovaWebViewImpl implements CordovaWebView {
} else {
intent.setData(uri);
}
- cordova.getActivity().startActivity(intent);
+ if (cordova.getActivity() != null) {
+ cordova.getActivity().startActivity(intent);
+ } else {
+ LOG.d(TAG, "Cordova activity does not exist.");
+ }
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
@@ -553,11 +563,15 @@ public class CordovaWebViewImpl implements CordovaWebView
{
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");
+ }
+ });
+ } else {
+ LOG.d(TAG, "Cordova activity does not exist.");
+ }
} catch (InterruptedException e) {
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]