Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening browser activity, but prevent it from being in the activity history

Tags:

android

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?

like image 519
jaredbro Avatar asked Aug 12 '10 01:08

jaredbro


People also ask

Why is my search history not showing up on Google?

Your activity doesn't show up If your searches, websites you've visited, or other activity don't appear in My Activity, make sure that: You're signed in. Activity is saved only when you're signed in to your Google Account. Your device is online.


1 Answers

Set the activity flag to Intent.FLAG_ACTIVITY_CLEAR_TOP after starting it. This way, the task will be deleted form the app stack so your main activity remains the top one on every new launch:

ctx.startActivity(webIntent);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
like image 115
Big Ali Avatar answered Oct 02 '22 14:10

Big Ali