How can I do this in Android. Activity & # 8594; WebBrowser & # 8594; Active, but click Back, you will not see WebBrowser

How can I make the web browser invoke a user circuit to start activity, then I want me to click the back button, but not return the web browser.

I just want to implement redirects when I call a web browser and then call my schema to trigger another action. When I get back I won’t like the web browser.

How can I do it?

Intent i = new Intent(Intent.ACTION_VIEW); i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); i.setData(Uri.parse(url)); startActivity(i); 

I already added it, but it does not work!

+6
android
source share
5 answers

This probably happens because the second action starts in the same task with which you launched the browser, which means that the beginning of the second action returns to the already existing task with the highest activity (activity 1) transferred to the back stack. See here .

If you make your second action run on another task, clicking back should complete this task and return to the task behind the browser.

To do this, you can use FLAG_ACTIVITY_NEW_TASK at the beginning of FLAG_ACTIVITY_NEW_TASK 2, or set the android:launchMode android:launchMode attribute to your manifest.

0
source share

As explained by other users, your activity is created in the browser stack. You cannot prevent the browser from opening its own stack, but you can do the same configuration in your application.

In your browser-triggered activity, add the following to your manifest file:

 android:allowTaskReparenting="true" android:launchMode="singleTask" 

This will cause your activity to be created in the application stack (and not in the browser). This will bring your application to the forefront.

android: launchMode = "singleTop" will not work, because it prevents the creation of a new action only if this activity is on top of the stack, which is not the case since the browser is at the top. android: launchMode = "singleTask" ensures that no other instances are created whether they are on top or not.

If you set Intent.FLAG_ACTIVITY_NO_HISTORY with the above configuration, everything should work fine, regardless of whether the browser is previously open or not. In the worst case, the browser will be at the bottom of the stack, and if you continue to hit, you will end up in the browser instead of exiting the application.

+6
source share

When you discover your intention, perhaps you can set it with a flag without a story

 intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
+1
source share

I found that only Intent.FLAG_ACTIVITY_NO_HISTORY works only if the browser has not started before. 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.

I tried adding a manifest to the android: launchMode = "singleTop" activity definition according to user634618. But that will not work. I do not understand why singleTop should help.

The documentation also states the following:

Blockquote As another example, the Android Browser application states that web browser activity should always open in its own task by specifying the singleTask launch mode in the element. This means that if your application gives the intention to open an Android browser, its activity will not be placed in the same task as your application. Instead, a new task is launched for the browser, or if the browser already has a task running in the background, this task is transferred to handle the new intent.

I think this is causing the problem. But how to make the browser launch in the current task?

0
source share

I also meet this problem. Here is the summary:

  • If the browser did not work before, it works well with the answers above; if the browser was launched earlier:
  • intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) DOES NOT work;
  • android:allowTaskReparenting="true" android:launchMode="singleTask" it looks like the browser is at the bottom of the action stack, but after exiting the application (using the BACK key), the browser starts up again.

So this problem still exists. I will send a message if I find a way to solve it.

0
source share

All Articles