views:

176

answers:

1

Android: i am using twitter authentication by launching webview

Intent authIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
startActivity(authIntent);

after successfull authentication onNewintent get call and control returns to my activity.

problem is webview still remain open after control return to my activity and if user press back button user can access that page again, how can i finish webview activity after control return to my actiivyt.

i would like to call finish on "authIntent" how can i ?

A: 

I preferred to launch the webview into a custom dialog and that way get full control over it. This includes using a WebView with a custom WebViewClient where the callback from authorization is handled in overridden shouldOverrideUrlLoading method.

For a detailed example, you could check the FacebookSDK and how it handles the authorization page in a dialog: it's a bit too much code to be pasted here.

totramon
any other quick fix to close intent launch by view flag ?
Faisal khan
I'm not aware (doesn't necessarily mean one doesn't exist) of a way to call an activity to finish. You could set the launch mode of the calling activity to singleTask in manifest, that way it won't get duplicated when the browser launches it again. I've used this successfully with phone calls, but I can't remember whether it worked the way I wanted with the browser and twitter.
totramon