'onBackPressed()' is deprecated in WebView

125 views Asked by At

My Application is Full WebView from HTML with some tools, I'm a Beginner, "'onBackPressed()' is deprecated" and that message shows when upgrade to SDK 33, I want to make BackPressed go back to the previous page in the application without closing the application

i tried the onBackPressed is deprecated - webView in android app

But still no solution

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView myWebView = findViewById(R.id.WebView);

    myWebView.loadUrl("file:///android_asset/index.html");
    myWebView.setWebChromeClient(new WebChromeClient());
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    webSettings.setLoadsImagesAutomatically(true);

} public void onBackPressed() {

    WebView webView = findViewById(R.id.WebView);
    if(webView.canGoBack()){
        webView.goBack();
    }else{
        super.onBackPressed();
    }
}
0

There are 0 answers