android - 使主页按钮调用 onFinish()

标签 android

我想做的就是在按下主页按钮时调用 onFinish(),我想这样做所以我总是在打开我的应用程序时进入主要 Activity ,我不希望用户跳回到他离开的地方(我知道在大多数情况下这是一个糟糕的概念,但对于我的应用来说,始终进入主要 Activity 更有意义)

谢谢!

最佳答案

您真正想要发生的是您的所有 Activity 都具有 android:noHistory=true 属性。

http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

android:noHistory : Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.

This attribute was introduced in API Level 3.

关于android - 使主页按钮调用 onFinish(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389343/

相关文章:

Android 谷歌地图按关键字搜索

安卓工作室 : Could not find any version that matches com. google.gms :play-services:6. 1.+

android - 在另一个 Activity 启动后,如何在一个 Android Honeycomb Activity 中释放 Drawable 内存?

android - 如何使用 onSearchRequested() 调用搜索对话框

android - 如何将应用程序置于后台?

android - 当 room android db 损坏时会发生什么?

javascript - 如何从android应用程序的webview访问设备摄像头

java - 当 grpcblockingstub 在截止日期内调用时如何管理应用程序崩溃

android - 在 Android 中绘制 3D 数学函数

android - 如何触发声音输入的振动?