|
2 | 2 |
|
3 | 3 | import android.app.Activity; |
4 | 4 | import android.app.Dialog; |
| 5 | +import android.content.Context; |
5 | 6 | import android.content.DialogInterface; |
| 7 | +import android.content.res.Resources; |
6 | 8 | import android.graphics.Color; |
7 | 9 | import android.graphics.Rect; |
8 | 10 | import android.graphics.drawable.ColorDrawable; |
@@ -192,9 +194,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c |
192 | 194 | applyWindowGravity(getDialog().getWindow(), "onCreateView"); |
193 | 195 | } |
194 | 196 |
|
195 | | - webView = new IterableWebView(getContext()); |
| 197 | + webView = createWebViewSafely(getContext()); |
| 198 | + if (webView == null) { |
| 199 | + dismissAllowingStateLoss(); |
| 200 | + return null; |
| 201 | + } |
196 | 202 | webView.setId(R.id.webView); |
197 | | - |
198 | 203 | webView.createWithHtml(this, htmlString); |
199 | 204 |
|
200 | 205 | if (orientationListener == null) { |
@@ -314,7 +319,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) { |
314 | 319 | */ |
315 | 320 | @Override |
316 | 321 | public void onStop() { |
317 | | - orientationListener.disable(); |
| 322 | + if (orientationListener != null) { |
| 323 | + orientationListener.disable(); |
| 324 | + } |
318 | 325 |
|
319 | 326 | super.onStop(); |
320 | 327 | } |
@@ -838,6 +845,18 @@ InAppLayout getInAppLayout(Rect padding) { |
838 | 845 | return InAppLayout.CENTER; |
839 | 846 | } |
840 | 847 | } |
| 848 | + |
| 849 | + private IterableWebView createWebViewSafely(Context context) { |
| 850 | + try { |
| 851 | + return new IterableWebView(context); |
| 852 | + } catch (Resources.NotFoundException e) { |
| 853 | + IterableLogger.e(TAG, "Failed to create WebView - system WebView resource issue", e); |
| 854 | + return null; |
| 855 | + } catch (RuntimeException e) { |
| 856 | + IterableLogger.e(TAG, "Failed to create WebView - unexpected error", e); |
| 857 | + return null; |
| 858 | + } |
| 859 | + } |
841 | 860 | } |
842 | 861 |
|
843 | 862 | enum InAppLayout { |
|
0 commit comments