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!
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.
When you open your Intent maybe you can set it with no-history flag
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With