mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-12 18:56:11 +08:00
Fix NPE caused by NetworkManager sending update before JS is ready.
This was happening for me when the device has been sleeping long enough to turn its networking off, and I start an app via adb.
This commit is contained in:
parent
6f873ff6b5
commit
5289d569b0
@ -219,6 +219,10 @@ public class NativeToJsMessageQueue {
|
|||||||
* Add a JavaScript statement to the list.
|
* Add a JavaScript statement to the list.
|
||||||
*/
|
*/
|
||||||
public void addPluginResult(PluginResult result, String callbackId) {
|
public void addPluginResult(PluginResult result, String callbackId) {
|
||||||
|
if (callbackId == null) {
|
||||||
|
Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Don't send anything if there is no result and there is no need to
|
// Don't send anything if there is no result and there is no need to
|
||||||
// clear the callbacks.
|
// clear the callbacks.
|
||||||
boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
|
boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
|
||||||
|
@ -206,9 +206,11 @@ public class NetworkManager extends Plugin {
|
|||||||
* @param connection the network info to set as navigator.connection
|
* @param connection the network info to set as navigator.connection
|
||||||
*/
|
*/
|
||||||
private void sendUpdate(String type) {
|
private void sendUpdate(String type) {
|
||||||
|
if (connectionCallbackId != null) {
|
||||||
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
|
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
|
||||||
result.setKeepCallback(true);
|
result.setKeepCallback(true);
|
||||||
this.success(result, this.connectionCallbackId);
|
this.success(result, this.connectionCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
webView.postMessage("networkconnection", type);
|
webView.postMessage("networkconnection", type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user