简体   繁体   English

Android 如何以编程方式按下后退按钮

[英]Android How to programmatically press the back button

How to programmatically press the back button.如何以编程方式按下后退按钮。 I have a small code that opens a tab in the Chrome browser.我有一个小代码可以在 Chrome 浏览器中打开一个选项卡。 After some time, if you press the back button on the phone with your hands, the open tab will close and my application will activate.一段时间后,如果您用手按下手机上的后退按钮,打开的选项卡将关闭,我的应用程序将激活。 How can I implement this programmatically?我如何以编程方式实现它? If you use this.onBackPressed(), then it will apply to my application will not lead to the desired result.如果您使用 this.onBackPressed(),那么它将应用于我的应用程序,不会导致预期的结果。 Here is the code on Kotlin with which I open the tab:这是 Kotlin 上的代码,我用它打开选项卡:

val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://www.google.ru/")
intent.setPackage("com.android.chrome")
startActivity(intent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM