android - 直通 Intent 过滤器和 Activity

标签 android android-intent android-activity intentfilter

我有一个隐式 Intent 过滤器,它通过使用默认 Web 浏览器打开要查看的 Intent 来处理 magnet: 方案链接。目前,这会产生这样的效果:单击磁力链接会将用户从浏览器中抛出到我的 Activity 中,而我的 Activity 会立即将他们带回带有新 URI 的浏览器中。

如何隐藏应用程序开关?在仅重定向回浏览器的 Activity 中看不到任何内容。

登陆浏览器中的新页面后按返回键,将使用户返回主屏幕。我希望它返回到单击磁力链接的原始页面。

这是 onCreate 中用于处理 Activity 的代码

String uri = "https://some.site";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(browserIntent);

我尝试了几个标志和finish(),但没有达到预期的效果。我相信我想放弃当前任务(启动浏览器 Intent 的任务),以便后退将直接返回到上一个任务。但如上所述,目前这只是让用户返回主屏幕。

最佳答案

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.

使用Theme.Translucent.NoTitleBar来获得不可见的 Activity 。不要在onCreate()中调用setContentView(),并在onCreate()底部调用finish().在 finish() 之前的某个地方,获取问题中的代码块。

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.

由于您没有编写 Web 浏览器,因此任务管理实际上不在您的控制范围内。如果启动您的 Activity 的 Web 浏览器将您置于单独的任务中,则这是 Web 浏览器的决定。 AFAIK,您无法说“不,我希望继续执行 Web 浏览器的任务”。请注意,此处的行为可能因浏览器而异。

关于android - 直通 Intent 过滤器和 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36811101/

相关文章:

android - 如何在不使用 textview 的情况下从 Hashmap 获取一个值到 Intent ?

Android:如何进行垂直合并?

Android:在启动器图标上显示通知

android - 如何打开并检查 Play Protect 是否启用或禁用

android - 通过 Intent 回到第一个 Activity,Activity 堆栈会发生什么情况?

android - 自定义 View 的 onMeasure : how to get width based on height

android - 在 ListView 中滚动时的日期分隔符

android - 识别发送 Intent 的位置

android - 如何返回到android中的父 Activity ?

android - 如何检查用户是否真正启动了 android 应用程序,而不仅仅是返回到 Activity ?