I have an implicit intent filter that handles magnet:
scheme links by opening an intent to view with the default web browser. Currently this has the effect that clicking a magnet link throws the user out of the browser into my activity, which immediately throws them back into the browser with a new URI.
How do I hide the app switch? There's nothing to see on the activity that comes up only to redirect back to the browser.
Pressing back after landing on the new page in the browser, throws the user back to the home screen. I want it to return to the original page where the magnet link was clicked.
Here's the code in onCreate
for the handling activity
String uri = "https://some.site";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(browserIntent);
I've tried several flags, and finish()
, which haven't had the intended effect. I believe I want to abandon the current task (the one that initiates the browser intent), so that backs will return directly to the previous task. But as mentioned above, currently this just drops the user back to the home screen.
How do I hide the app switch? There's nothing to see on the activity that comes up only to redirect back to the browser.
Use Theme.Translucent.NoTitleBar
to have an invisible activity. Do not call setContentView()
in onCreate()
, and at the bottom of onCreate()
, call finish()
. Somewhere before finish()
, have your chunk of code from your question.
I believe I want to abandon the current task (the one that initiates the browser intent), so that backs will return directly to the previous task. But as mentioned above, currently this just drops the user back to the home screen.
Since you did not write the Web browser, task management is outside of your control, really. If the Web browser launching your activity puts you in a separate task, that's the Web browser's decision to make. You have no way of saying "no, I wish to remain in the Web browser's task", AFAIK. And note that the behavior here may vary by browser.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments