lblasa
lblasa

Reputation: 6374

How to close browser activity when returning to calling activity?

I have this situation. I have an Activity A that sends an intent to create an Activity B which is a browser to authenticate a user with his twitter account. When credentials are submitted the control goes back again to Activity A and I can keep navigating through the app. However, if the users leaves the app, the browser activity is being resumed, forcing the user to close the browser.

The problem is that I would like to remove the browser activity from the stack once I get the authentication credentials.

Do you know if this is possible? I cannot use startActivityForResult since the authentication needs to be made in the browser, I don't have any control over that activity. Thanks a lot

EDIT:

I'm starting the activity like this:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)).setFlags(Intent.FILL_IN_ACTION));

Upvotes: 4

Views: 1497

Answers (1)

Dan O
Dan O

Reputation: 11

Maybe you could put something in OnResume() in Activity B which checks if this is the first activation of Activity B, and closes it automatically if it isn't?

Update: You could alternatively use an AsyncTask to post the credential info to the website, using a DefaultHttpClient and HttpPost. Unfortunately I've only used HttpGet in this scenario, but there is some code here that may be of use.

Upvotes: 1

Related Questions