Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My application keeps on crashing using Webview?

I'm just testing my application at the moment. However, it keeps on crashing on the loading screen. Once it loads it redirects to the login or users account if they have already logged in.

However, I keep getting these error messages in android studios console log when built the application.

W/cr_CrashFileManager: /data/user/0/chrisbeckett.********/cache/WebView/Crash Reports does not exist or is not a directory

// I've put the stars as I can't show the name of the application yet. 
W/cr_AwContentsClient: Denied starting an intent without a user gesture, URI http://********.********.com/login

My current code:

package chrisbeckett.**********;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;// Instance of WebChromeClient for handling all chrome functions.
    private volatile WebChromeClient mWebChromeClient;


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

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setDomStorageEnabled(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        webSettings.setAppCacheEnabled(true);
        webSettings.setAppCacheMaxSize(100 * 1000 * 1000);

        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.loadUrl("http://********.*********.com/loading");
    }

    /**
     * Set the WebChromeClient.
     * @param client An implementation of WebChromeClient.
     */
    public void setWebChromeClient(WebChromeClient client) {
        mWebChromeClient = client;
    }
}

Further information:

My code works on all web browsers on a desktop when viewing it in a mobile mode in the inspector when testing before putting it in App format.

If you require any more information please let me know.

like image 941
YaBCK Avatar asked Dec 01 '17 11:12

YaBCK


People also ask

Why is WebView crashing?

As per the company and reported by 9to5 Google, a “bug within Chrome & WebView's experiment & configuration technology" was the culprit. The bug essentially caused “instability" in Android apps that use WebView to render web content that, in turn, repeatedly crashed them.

How do I fix System WebView?

You might often face issues in updating the chrome and Android System Webview. To fix this problem, you can reboot your device, check your internet connection, stop auto-updating all apps, clear Google Playstore cache, and storage, leave the beta testing program, and manually update Android WebView app from Playstore.

Should I disable WebView?

Lastly, Google returned WebView duties to Android System WebView for Android 10, Android 11, and now Android 12. So if you are running any of these systems (or Android 6.0 Marshmallow or earlier), we strongly recommend you don't disable the app or delete its updates.


1 Answers

try below code this may work

mWebView.setWebViewClient(new WebViewClient() {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;                
    }

});
like image 170
Omkar Avatar answered Sep 26 '22 18:09

Omkar