简体   繁体   English

Android Home Button禁用后退

[英]Android Home Button disable back

if a user tapped the home button and open the app after that, how to not allow back? 如果用户点击主页按钮并在此之后打开应用程序,如何不允许返回? eg don't allow users to go back to screens that they seen before tapping the home button. 例如,不要让用户在点击主页按钮之前返回他们看到的屏幕。 It should be treated as a new session 它应该被视为一个新的会话

This sounds like a bad idea, as it blatantly goes against the Android task/navigation guidelines. 这听起来像个坏主意,因为它公然反对Android任务/导航指南。

The user expects to be able to back out to the previous screen after resuming a task... and preventing it will potentially piss off a lot of users. 用户希望能够在恢复任务后退回到上一个屏幕...并且防止它可能会惹恼许多用户。

Please, please, please read these documents before you risk destroying the user experience. 请,请, 你就有可能破坏用户体验,之前阅读这些文档。

The home button cannot be overridden nore should it, if you dont want the user to go back to the activity they left when the home button was clicked then on the on pause of the activity just pop the backstack to where you want to be. 如果你不希望用户回到他们在点击主页按钮时离开的活动,那么主页按钮就不能被覆盖,然后在活动的暂停时只需将backstack弹出到你想要的位置。

see this answer 看到这个答案

If you want to end your Activity once it is no longer visible then finish your activity in your Activities call to onStop(). 如果您想在活动不再可见时结束活动,请在活动调用onStop()中完成活动。

@Override
    protected void onStop() {
        super.onStop();

    this.finish();
}

This will finish your Activity with no chance of onRestart() being called. 这将完成您的Activity而不会被调用onRestart()。 Be careful with this method because users expect to resume the app instead of having to start over, but there are cases where this would be the accepted protocol. 请小心使用此方法,因为用户希望恢复应用程序而不必重新开始,但有时这将是接受的协议。 See more on Navigation and the Activity LifeCycle . 详细了解NavigationActivity LifeCycle

Edit: Also see the question Android-Quittings an application - is that frowned upon? 编辑:还看到问题Android-Quittings一个应用程序 - 是不是很不满意? specifically this answer . 特别是这个答案

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

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