Below I posted my current onRenderProcessGone.
- In the
if (!detail.didCrash()) {}
the instance variable "view" is guaranteed to be null, it's safe to reinitialize it. Should I myself reinitialize it or system will do it? Could you specify the example of logic for how the app can continue executing? How to handle the crash more gracefully?
@TargetApi(Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { // WebViewClient.onRenderProcessGone was added in O. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return false; } super.onRenderProcessGone(view, detail); if (!detail.didCrash()) { // Renderer was killed because the system ran out of memory. // The app can recover gracefully by creating a new WebView instance // in the foreground. Log.e("MY_APP", "System killed the WebView rendering process " + "to reclaim memory. Recreating..."); if (view != null) { ((ViewGroup)view.getParent()).removeView(view); view.destroy(); view = null; } // By this point, the instance variable "view" is guaranteed // to be null, so it's safe to reinitialize it. return true; // The app continues executing. } // Renderer crashed because of an internal error, such as a memory // access violation. Log.e("MY_APP", "The WebView rendering process crashed!"); // In this example, the app itself crashes after detecting that the // renderer crashed. If you choose to handle the crash more gracefully // and allow your app to continue executing, you should 1) destroy the // current WebView instance, 2) specify logic for how the app can // continue executing, and 3) return "true" instead. return false; }