Created
May 21, 2019 18:31
-
-
Save andreban/e6aaab7536c20b32fb5f7d12c3697874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context=".MainActivity"> | |
<WebView | |
android:id="@+id/webview" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Crash" | |
android:layout_gravity="center" | |
android:onClick="crash"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.hellowebviewjava; | |
import android.os.Build; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.webkit.RenderProcessGoneDetail; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
public class MainActivity extends AppCompatActivity { | |
private WebView mWebView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mWebView = findViewById(R.id.webview); | |
mWebView.setWebViewClient(new WebViewClient() { | |
@Override | |
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { | |
return super.onRenderProcessGone(view, detail); | |
} | |
super.onRenderProcessGone(view, detail); | |
if (view != null) { | |
((ViewGroup) view.getParent()).removeView(view); | |
view.destroy(); | |
view = null; | |
} | |
return true; | |
} | |
}); | |
mWebView.loadUrl("https://www.example.com"); | |
} | |
public void crash(View v) { | |
if (mWebView != null) { | |
mWebView.loadUrl("chrome://crash"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment