Skip to content

Commit 6662d7d

Browse files
[SDK-368] Fix in-app creation causing crash due to problems with webview (#999)
1 parent 12e0056 commit 6662d7d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.app.Dialog;
55
import android.content.Context;
66
import android.content.DialogInterface;
7+
import android.content.res.Resources;
78
import android.graphics.Color;
89
import android.graphics.Point;
910
import android.graphics.Rect;
@@ -200,9 +201,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
200201
applyWindowGravity(getDialog().getWindow(), "onCreateView");
201202
}
202203

203-
webView = new IterableWebView(getContext());
204+
webView = createWebViewSafely(getContext());
205+
if (webView == null) {
206+
dismissAllowingStateLoss();
207+
return null;
208+
}
204209
webView.setId(R.id.webView);
205-
206210
webView.createWithHtml(this, htmlString);
207211

208212
if (orientationListener == null) {
@@ -324,7 +328,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
324328
*/
325329
@Override
326330
public void onStop() {
327-
orientationListener.disable();
331+
if (orientationListener != null) {
332+
orientationListener.disable();
333+
}
328334

329335
super.onStop();
330336
}
@@ -747,6 +753,18 @@ InAppLayout getInAppLayout(Rect padding) {
747753
return InAppLayout.CENTER;
748754
}
749755
}
756+
757+
private IterableWebView createWebViewSafely(Context context) {
758+
try {
759+
return new IterableWebView(context);
760+
} catch (Resources.NotFoundException e) {
761+
IterableLogger.e(TAG, "Failed to create WebView - system WebView resource issue", e);
762+
return null;
763+
} catch (RuntimeException e) {
764+
IterableLogger.e(TAG, "Failed to create WebView - unexpected error", e);
765+
return null;
766+
}
767+
}
750768
}
751769

752770
enum InAppLayout {

0 commit comments

Comments
 (0)