Eddie Martinez
Eddie Martinez

Reputation: 13910

closing webview in android

I am using Twitter4j but I need to authenticate a user with oAuth. The user needs to get a pin and input it into the app. When I load a webview with the url and the user accept's to give the app privileges, they receive a pin. How would they close the webview in order to input the pin. I cant close the webview in the emulator. Below is the method in the Async class where the webview is shown after the url is retrieved.

 protected void onPostExecute(String url) {

        WebView webview = new WebView(MainActivity.this);
        setContentView(webview);
        webview.loadUrl(url);


    }

Upvotes: 3

Views: 28294

Answers (5)

Mukesh V Sonawane
Mukesh V Sonawane

Reputation: 11

Add a close button and on its click set:

webview.setVisibility(View.INVISIBLE);   
webview.loadUrl("");   

You can then reduce the height width of the web view to minimum.

Upvotes: 1

Amos
Amos

Reputation: 2640

This works for me:

webview.destroy();

Upvotes: 2

Hany Sakr
Hany Sakr

Reputation: 2929

You can call finish() from anywhere inside the Activity class

Upvotes: 1

kiruwka
kiruwka

Reputation: 9450

Well, you could

  • instead use another dedicated activity with mainly a webview [potentially also with 'done' button]. You could start that activity from your onPostExecute with intent, and then you will go back when user is done with it, or you could start that webview activity for result

  • Another option is to replace your webview when you are done with another view, for example by calling setContentView with another layout. I never did this myself, and not sure it will work easily, but I found that some people recommend using ViewFlipper for similar effect.

Hope that helps.

Upvotes: 2

user3050828
user3050828

Reputation:

You can't "close" a WebView. What you could do is hide it. Maybe this solution will shed some light - Hide WebView until JavaScript is done

Upvotes: 3

Related Questions