mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-23 01:06:23 +08:00
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 <rick.habets@kbc.be>
This commit is contained in:
parent
9dcf3eb68b
commit
19a5feb875
@ -176,13 +176,16 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If timeout, then stop loading and handle error
|
// If timeout, then stop loading and handle error (if activity still exists)
|
||||||
if (loadUrlTimeout == currentLoadUrlTimeout) {
|
if (loadUrlTimeout == currentLoadUrlTimeout && cordova.getActivity() != null) {
|
||||||
cordova.getActivity().runOnUiThread(loadError);
|
cordova.getActivity().runOnUiThread(loadError);
|
||||||
|
} else if (cordova.getActivity() == null) {
|
||||||
|
LOG.d(TAG, "Cordova activity does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (cordova.getActivity() != null) {
|
||||||
final boolean _recreatePlugins = recreatePlugins;
|
final boolean _recreatePlugins = recreatePlugins;
|
||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -192,6 +195,9 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
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 {
|
} else {
|
||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
}
|
}
|
||||||
|
if (cordova.getActivity() != null) {
|
||||||
cordova.getActivity().startActivity(intent);
|
cordova.getActivity().startActivity(intent);
|
||||||
|
} else {
|
||||||
|
LOG.d(TAG, "Cordova activity does not exist.");
|
||||||
|
}
|
||||||
} catch (android.content.ActivityNotFoundException e) {
|
} catch (android.content.ActivityNotFoundException e) {
|
||||||
LOG.e(TAG, "Error loading url " + url, e);
|
LOG.e(TAG, "Error loading url " + url, e);
|
||||||
}
|
}
|
||||||
@ -553,11 +563,15 @@ public class CordovaWebViewImpl implements CordovaWebView {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
if (cordova.getActivity() != null) {
|
||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
pluginManager.postMessage("spinner", "stop");
|
pluginManager.postMessage("spinner", "stop");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
LOG.d(TAG, "Cordova activity does not exist.");
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user