diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java index c3660265e..dcb1b56af 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java @@ -24,7 +24,13 @@ protected void onCreate(Bundle savedInstanceState) { bridgeBuilder.setInstanceState(savedInstanceState); getApplication().setTheme(R.style.AppTheme_NoActionBar); setTheme(R.style.AppTheme_NoActionBar); - setContentView(R.layout.bridge_layout_main); + try { + setContentView(R.layout.bridge_layout_main); + } catch (Exception ex) { + setContentView(R.layout.no_webview); + return; + } + PluginManager loader = new PluginManager(getAssets()); try { @@ -67,8 +73,10 @@ public void onSaveInstanceState(Bundle outState) { public void onStart() { super.onStart(); activityDepth++; - this.bridge.onStart(); - Logger.debug("App started"); + if (this.bridge != null) { + this.bridge.onStart(); + Logger.debug("App started"); + } } @Override @@ -81,36 +89,43 @@ public void onRestart() { @Override public void onResume() { super.onResume(); - bridge.getApp().fireStatusChange(true); - this.bridge.onResume(); - Logger.debug("App resumed"); + if (bridge != null) { + bridge.getApp().fireStatusChange(true); + this.bridge.onResume(); + Logger.debug("App resumed"); + } } @Override public void onPause() { super.onPause(); - this.bridge.onPause(); - Logger.debug("App paused"); + if (bridge != null) { + this.bridge.onPause(); + Logger.debug("App paused"); + } } @Override public void onStop() { super.onStop(); - - activityDepth = Math.max(0, activityDepth - 1); - if (activityDepth == 0) { - bridge.getApp().fireStatusChange(false); + if (bridge != null) { + activityDepth = Math.max(0, activityDepth - 1); + if (activityDepth == 0) { + bridge.getApp().fireStatusChange(false); + } + + this.bridge.onStop(); + Logger.debug("App stopped"); } - - this.bridge.onStop(); - Logger.debug("App stopped"); } @Override public void onDestroy() { super.onDestroy(); - this.bridge.onDestroy(); - Logger.debug("App destroyed"); + if (this.bridge != null) { + this.bridge.onDestroy(); + Logger.debug("App destroyed"); + } } @Override diff --git a/android/capacitor/src/main/res/layout/no_webview.xml b/android/capacitor/src/main/res/layout/no_webview.xml new file mode 100644 index 000000000..7228cc2fc --- /dev/null +++ b/android/capacitor/src/main/res/layout/no_webview.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/android/capacitor/src/main/res/values/strings.xml b/android/capacitor/src/main/res/values/strings.xml index 854200555..2db1111db 100644 --- a/android/capacitor/src/main/res/values/strings.xml +++ b/android/capacitor/src/main/res/values/strings.xml @@ -1,2 +1,3 @@ + This app requires a WebView to work