tags:

views:

56

answers:

1

I'm working on an app that launches the browser activity to perform a Twitter OAuth authorization. This process uses a callback url which will re-launch the activity that started the browser activity in the first place.

My problem is that the browser pages remain in the history stack and when the user then clicks back from the preferences activity that launched the browser in the first place, they don't go back to the app's main activity, but instead are brought back to the browser. I've tried adding flags to the launching intent to prevent history and reset on clear, but it doesn't seem to work when running on my phone, only on the emulators.

Here is the code I'm using to launch the browser activity:

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

            webIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            webIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            webIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

            ctx.startActivity(webIntent);

Anyone have any idea what might be wrong?

+1  A: 

call

finish();

after

ctx.startActivity(webIntent);
Mathias Lin
That will close the activity that I actually want to stay open, here is a sequence of events.App starts with a MainActivity, the user opens PreferencesActivity, then the user clicks Authorize Twitter which launches the browser activity with the above code, passing it a callback url that PreferencesActivity has an intent filter to handle. User logins into Twitter, authorizes it to be used by the app and the browser runs the callback url which re-activates PreferencesActivity through it's intent filter. At this time, if the user clicks the 'Back' key, I want it to go back to MainActivity.
jaredbro
Why do you reactivate PreferencesActivity with the IntentFilter instead of using startActivityForResult ? I'm not sure if it would work in your case as I don't know the details of your code, but might that be an idea? This way you'd actually really going back in the stack history rather than opening another instance of PreferencesActivity. Not sure though if that's what it does right now, easier to see with the complete code, callbacks, intent-filters, etc.
Mathias Lin