H
H
Hash1334202020-06-20 16:56:03
Java
Hash133420, 2020-06-20 16:56:03

How to automatically close a webview when an error is thrown in it?

I don’t understand at all how to close the webview if an error pops up from the user

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browser);

        WebView webView = findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
       webView.loadUrl("http://keygarbx.beget.tech");

        WebViewClient webViewClient = new WebViewClient(){
            @SuppressWarnings("deprecation")
            public boolean ShouldOverrideUrlLoading(WebView view, String url){
                view.loadUrl(url);
                return  true;
            }

            @TargetApi(Build.VERSION_CODES.N)
            public boolean ShouldOverrideUrlLoading(WebView view, WebResourceRequest request){
                view.loadUrl(request.getUrl().toString());
                return true;
            }

            

        };


        
        webView.setWebViewClient(webViewClient);

        Button webback = (Button)findViewById(R.id.webback);
        webback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    Intent intent = new Intent(BrowserActivity.this, MainActivity.class);
                    startActivity(intent);finish();
                }catch (Exception e) {
                } // конец конструкции
            }
        });






    }
  @Override
    public void onBackPressed(){
    try{
        Intent intent = new Intent(BrowserActivity.this, MainActivity.class);
        startActivity(intent);finish();
    }catch (Exception e) {
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question