Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.iterable.iterableapi.ui.inbox;

import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebView;
import android.webkit.WebViewClient;

Expand All @@ -22,6 +25,7 @@
public class IterableInboxMessageFragment extends Fragment {
public static final String ARG_MESSAGE_ID = "messageId";
public static final String STATE_LOADED = "loaded";
private static final String TAG = "IterableInboxMsgFrag";

private String messageId;
private WebView webView;
Expand Down Expand Up @@ -100,5 +104,31 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}
return true;
}

@Override
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
boolean didCrash = detail.didCrash();
Log.w(TAG, "WebView render process gone. didCrash: " + didCrash);

// Clean up the WebView to prevent further issues
if (view != null) {
try {
view.destroy();
} catch (Exception e) {
Log.e(TAG, "Error destroying WebView after render process gone", e);
}
}

// Close the fragment's activity since the WebView is no longer usable
if (getActivity() != null) {
getActivity().finish();
}

// Return true to prevent the app from crashing
return true;
}
return super.onRenderProcessGone(view, detail);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.iterable.iterableapi;

import android.os.Build;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebView;
import android.webkit.WebViewClient;

class IterableWebViewClient extends WebViewClient {
private static final String TAG = "IterableWebViewClient";

IterableWebView.HTMLNotificationCallbacks inAppHTMLNotification;

IterableWebViewClient(IterableWebView.HTMLNotificationCallbacks inAppHTMLNotification) {
Expand All @@ -21,4 +25,25 @@ public void onPageFinished(WebView view, String url) {
inAppHTMLNotification.setLoaded(true);
view.postDelayed(inAppHTMLNotification::runResizeScript, 100);
}
}

@Override
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
boolean didCrash = detail.didCrash();
IterableLogger.w(TAG, "WebView render process gone. didCrash: " + didCrash);

// Clean up the WebView to prevent further issues
if (view != null) {
try {
view.destroy();
} catch (Exception e) {
IterableLogger.e(TAG, "Error destroying WebView after render process gone", e);
}
}

// Return true to prevent the app from crashing
return true;
}
return super.onRenderProcessGone(view, detail);
}
}
Loading