How to check if the webView has loaded the next page in Android?

android, android-studio, android-webview

Solution

You can set a callback with `WebViewClient` as below:

mWebView.setWebViewClient(new WebViewClient() {

   public void onPageFinished(WebView view, String url) {
        // do your stuff here
    }
});

Problem

When the application is opened a webView opens say "www.google.com". If the user types in some query and presses Search(in the WebView itself, not an Android button) the next page loads. Now my need is to know if the webView has loaded the next page that is the search results for the query. Is there any built-in method to check that? EDIT 1 Implementing the method of Asuthosh Panda and Chintan Soni. It still doesn't work. This is implemented in a fragment. Does that affect the code in any way? ``` public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment String url; //String urrrl=null; View view = inflater.inflate(R.layout.fragment_net_con, container, false); myWebView = (WebView)view.findViewById(R.id.webView21); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("https://www.google.com"); myWebView.setWebViewClient(new WebViewClient()); url=myWebView.getUrl().toString(); Log.d("My app msg","I am here"); Log.d("URL ",url); if(url.contains("q=")){ System.exit(1); } activityCommander.setwebs(myWebView.getUrl()); return view; } ```

Original source