Android 12 - 打开 https 意图会导致应用程序重新启动 Activity,然后启动浏览器
我发现奇怪的行为仅发生在 Android 12 设备上。
- 在应用程序的
Fragment
中,我们点击在浏览器中打开一个链接,如下所示:Intent(Intent.ACTION_VIEW, Uri.parse(link))
然后startActivity(intent)
- 该链接指向我们自己的网站,该网站已验证主机。
- 然后发生的事情是
MainActivity
被销毁并重新启动,然后浏览器打开。 - 该应用程序基于具有
Fragments
的单个 Activity,并且具有launchMode=singleTask
- 运行 Android 12 以外的设备,只需打开浏览器,返回时应用程序位于最后一个 < code>Fragment 访问 - 这是期望的行为,也是我所期望的。
需要注意的是,该应用程序可以正确处理深层链接。它还启用了 autoVerify,并且 assetLinks.json 的设置正确 - 单击链接时应用程序会自动打开。
我的想法是,围绕深层链接和 autoVerify 引入的更改一定是导致这种情况的原因。如果我们将链接替换为 https://www.google.com
,它不会破坏 MainActivity
,我们可以访问该网站并返回应用程序。与我们的主机之一的任何其他链接都会导致该行为。
好奇是否有人有相同的经历。我们正在考虑在内部打开一个网络视图来避免这种情况作为临时解决方案,但这样做并不理想。
I'm seeing a strange behaviour only happening on android 12 devices.
- In a
Fragment
of the app we tap to open a link in the browser like this:Intent(Intent.ACTION_VIEW, Uri.parse(link))
and thenstartActivity(intent)
- The link is to our own website which has the host verified.
- What happens then is the
MainActivity
is destroyed and restarted and afterwards, the browser opens. - The app is based on a single activity with
Fragments
and haslaunchMode=singleTask
- Devices running other than android 12 just open the browser and when going back the app is at the last
Fragment
visited - this is the desired behaviour and what I would expect as well.
A note on this is that the app handles deep links correctly. It also has the autoVerify enabled and the setup for the assetLinks.json is correct - the app open automatically when clicking a link.
My lines of thought is that the changes introduced around deep links and autoVerify
must be causing this. If we swap the link for https://www.google.com
it doesn't destroy the MainActivity
and we can visit the website and go back to the app. Any other link with one of our hosts causes that behaviour.
Curious if anyone has experience the same. We are thinking in opening a webview inside to avoid this as a temporal solution but it wouldn't be ideal to do so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论