覆盖Android的后退按钮按钮、Android

2023-09-12 04:46:21 作者:住进你眼睛

为什么我试图做到这一点了信息:我使用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.

如果你仍然想这样做,请参阅#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.

您可能会发现一些灵感here.

You might find some inspiration from here.