Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android close current activity from WebView

This problem fixed This problem fixed

like image 838
Meysam Valiolahi Avatar asked Dec 05 '14 11:12

Meysam Valiolahi


People also ask

How do I close Webview?

Add a close button and on its click set: webview. setVisibility(View. INVISIBLE); webview.

Is Android Webview deprecated?

It was deprecated in API level 21.

What is Webview activity?

WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your application using WebView. WebView makes turns your application to a web application.


1 Answers

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; 
}
like image 151
Murtaza Khursheed Hussain Avatar answered Sep 27 '22 02:09

Murtaza Khursheed Hussain