Opening browser activity, but does not allow it to be in the activity history

I am working on an application that launches browser activity to authorize Twitter OAuth. This process uses a callback URL that re-launches the activity, which first launches the activity of the browser.

My problem is that the browser pages remain on the history stack, and when the user then discards from the activity the preferences that launched the browser in the first place, they do not return to the main action of the application, but instead are returned to the browser. I tried adding flags to the launch intent to prevent history and reset on clarity, but it doesn't seem to work when working on my phone, only on emulators.

Here is the code I use to trigger 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); 

Can anyone understand what might be wrong?

+6
android
source share
4 answers

Set the activity flag Intent.FLAG_ACTIVITY_CLEAR_TOP after it starts. Thus, the task will be removed from the application stack, so your main action will remain the first with each new start:

 ctx.startActivity(webIntent); browserIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
+2
source share

Call

 finish(); 

after

 ctx.startActivity(webIntent); 
0
source share

Hi, I have the same problem at the moment. I think the solution is to trigger the action you want to return to with a special flag:

 Intent intent = new Intent(this, acticityToReturnTo.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); 

The problem is that this does not work (at least on 1.6). But maybe someone will find a solution for this. I think FLAG_ACTIVITY_CLEAR_TOP is exactly what we are.

0
source share

I found that Intent.FLAG_ACTIVITY_NO_HISTORY only works if the browser has not previously run. If I restart Android and run the application that calls the browser, everything works fine. But when I launch the browser in front of my application, the browser will remain in history.

Here is a related question, but without a really working solution

How can I do this in Android. Activity β†’ WebBrowser β†’ Active, but click Back and you won’t see a web browser

0
source share

All Articles