android close current activity from WebView

This problem fixed This problem fixed


Solution 1:

If you can redirect on button click something

then

onClick="document.location.href='http://exitme';".

Then in your shouldOverrideUrlLoading method, you can intercept that URL and exit the app.

@Override 
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
    if (url.contains("http://exitme")
        finish();  // close activity
    else
        view.loadUrl(url);

    return true; 
}

Solution 2:

You have to inject JS interface in your WebView. Here is an example, how to catch button click in your HTML page and catch this action in Java (Android).