覆盖Android的后退按钮 [英] Override Android Back Button

查看:183
本文介绍了覆盖Android的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我试图做到这一点了信息:我使用ActivityGroups打开从tabHost活动的活动,并有一个选项卡下的新活动的住宿。这部分我已经得到了。但是,当在新的活动,如果我使用后退按钮需要我的权利出片的活动,所以我必须单击几次要回我在那里。

A little info as to why I am attempting to do this: I am using ActivityGroups to open an activity from a tabHost activity and have that new activity stay under the tabs. That part i've got. But when in that new activity, if I use the back button it takes me right out of the tabs activity so I have to click a few times to get back to where I was.

有没有一种方法来设置后退按钮去一个特定的活动,而不是杀死当前活动窗口?

Is there a way to set the back button to go to a specific activity rather than killing the current activity window?

推荐答案

在一般情况下,我建议不要因为它打破了UX。用户期望后退按钮杀整个窗口,特别是因为你使用的是tabhost。对于用户来说,整个束(标签和所有的)是,他想,当他点击后退按钮退出单个活动。

In general, I would advise against that because it breaks the UX. The user expects the back button to kill the entire window, especially since you are using the tabhost. To the user, the entire bunch (tabs and all) is a single activity that he wants to exit when he hits the back button.

如果你仍然想这样做,请参阅<一个href="http://developer.android.com/reference/android/app/Activity.html#onBack$p$pssed%28%29">#onBack$p$pssed().这就是所谓的活动时检测到用户的$ P $返回键的PSS。默认为完成活动,但你可以把它做任何你想要的。我劝小心和谨慎。

If you still want to do it, refer to #onBackPressed(). It is called when the activity has detected the user's press of the back key. The default is to finish the activity, but you can make it do whatever you want. I advise care and caution.

您可能会发现一些灵感<一href="http://stackoverflow.com/questions/2000102/android-override-back-button-to-act-like-home-button">here.

You might find some inspiration from here.

这篇关于覆盖Android的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆