Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView : WebViewClient.onPageStarted method is not called

Please help me this question. I am working with webview. And I faced two problem :

  1. When the webview loading new page. The onPageStarted method is not called but the onPageFinished method is called.
  2. The method :mWebView.canGoBack() always return false.

If you know why or have any suggest please help me. Note : I am working with : Jquery Mobile in server side(Web side).

Those are my Webview client and Webview init source code.

    private class MyWebViewClient extends WebViewClient{

    private static final String TAG = "MyWebViewClient";


    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        Log.v(TAG, "onPageFinished url: " + url);

    }

    @Override
    public void onLoadResource(WebView view, String url){
        Log.v(TAG, "onLoadResource url: " + url);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        Log.v(TAG, "onPageStarted url: " + url);

    }

    @Override
    public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl) {
        super.onReceivedError(view, errorCode, description, failingUrl);
        Log.v(TAG, "onReceivedError url: " + failingUrl);

    }


    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.v(TAG, "shouldOverrideUrlLoading : " + url);

        return false;
    }

}

This is my webview init :

            mWebView =  new WebView(getActivity());
        mWebView.setWebViewClient(new MyWebViewClient());
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        String link = getArguments().getString(PARAMETER_LINK);
        boolean deleteWVData = getArguments().getBoolean(PARAMETER_DELETE_DATA);
        if(deleteWVData)
            mWebView.clearCache(true);
like image 342
gZerone Avatar asked Oct 08 '12 18:10

gZerone


1 Answers

I believe onPageStarted is only called when a new page is loaded. E.g.g you are on index.html and navigate to contact.html

Most mobile frameworks (like, jquery mobile, ionic, angualar) will stay on the index.html page and only modify the content. Hence, onPageStarted is not called, but onPageFinished is

like image 84
Entreco Avatar answered Sep 30 '22 13:09

Entreco