Java – WebView What event handles (watches) URL changes – Android

The app does a login to a web application using WebView. Once in the webview, the webview appears to handle everything for you as it should based on the user’s clicks. However I need to review on each event if the URL changes to a specific logout URL.

How can I return the user to the app itself when the user logs out on the web application within the webview? I do not want the webview to stay as the active view.

I have tried WebViewClient.shouldOverrideUrlLoading and View.OnTouchListsner.

The class I tried to implement public but it didn’t allow me.

class myWebClient extends WebViewClient
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub

                return true;


            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);


Here’s the code before I want to call the method to check the URL;

public void onCreate(Bundle savedInstanceState) {
        final EditText phone = (EditText) findViewById(;
        final EditText login = (EditText) findViewById(;
        final EditText pass = (EditText) findViewById(;
        final Context context = this;
        submit  = (Button)findViewById(;
        sbutton = (Button)findViewById(;
        chcred = (CheckBox) findViewById(;
        webView = (WebView) findViewById(;
        webView.setWebViewClient(new WebViewClient());
        submit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                textstring(phone, login, pass);
                encPhone = URLEncoder.encode(Phone);
                encLogin = URLEncoder.encode(Login);
                encPass = URLEncoder.encode(Pass);

                if (chcred.isChecked()) {
                    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                clear(phone, login, pass);

        WebViewClient() //Right here is where I want to call it


This can help you:, java.lang.String,

The event does not notify you when the url changes, but does when the page starts to load, at that point you only need to verify the current url.

Source: stackoverflow