diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 21cbf939..ebbae4ca 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -714,17 +714,19 @@ private static synchronized void sendJavascript(final String js) { } final CordovaWebView view = webView.get(); - - ((Activity) (view.getContext())).runOnUiThread(new Runnable() { - public void run() { - view.loadUrl("javascript:" + js); - View engineView = view.getEngine().getView(); - - if (!isInForeground()) { - engineView.dispatchWindowVisibilityChanged(View.VISIBLE); + + if (view != null) { + ((Activity) (view.getContext())).runOnUiThread(new Runnable() { + public void run() { + view.loadUrl("javascript:" + js); + View engineView = view.getEngine().getView(); + + if (!isInForeground()) { + engineView.dispatchWindowVisibilityChanged(View.VISIBLE); + } } - } - }); + }); + } } /** @@ -737,6 +739,10 @@ public static boolean isInForeground() { CordovaWebView view = webView.get(); + if (view == null) { + return false; + } + KeyguardManager km = (KeyguardManager) view.getContext().getSystemService(Context.KEYGUARD_SERVICE); // noinspection SimplifiableIfStatement