Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do that in Android. Activity -> WebBrowser -> Acrivity, but Press Back not see the WebBrowser

Tags:

android

How can I do that the web browser call a custom scheme to start a activity, then I want I press the Back Button but not return the web browser.

I just want to implement forwarding when I call a web browser then call my scheme to start another Activity. When I back, I will not like to see the web browser.

How should I do that?

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 not works!

like image 518
HiMing Avatar asked Mar 16 '11 14:03

HiMing


2 Answers

As explained by other users, your Activity is being created on the browser's stack. You cannot prevent the browser from opening on its own stack, but you can do the same configuration on your application.

In your activity that is called by the browser, add the following in your manifest file:

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

This will make your activity to be created on your application stack (instead of the browser's). This will basically bring your application back to the front.

android:launchMode="singleTop" will not work because it prevents creating a new activity only if that activity is on top of the stack, which is not the case as the browser is the one currently at the top. android:launchMode="singleTask" will ensure no other instances are created regardless of them being on top or not.

If you set the Intent.FLAG_ACTIVITY_NO_HISTORY with the configuration above then everything should work fine, regardless of the browser being previously open or not. In the worst case, the browser will be at the bottom of the stack and if you keep hitting back you would eventually reach the browser instead of exiting the application.

like image 72
AngraX Avatar answered Nov 15 '22 00:11

AngraX


When you open your Intent maybe you can set it with no-history flag

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
like image 24
papachan Avatar answered Nov 14 '22 23:11

papachan