onBack pressed隐藏不破坏活动 [英] onBackPressed to hide Not destroy activity
问题描述
我知道如何取消返回键preSS,使活动/主窗口中保持可见:
i know how to cancel back keypress, so that the activity / main window stays visible:
public void onBackPressed() {
return;
}
我的目的不过是隐藏的活动,没有完成它,你怎么做,在onBack pressed事件?
my aim is to hide the activity, however, without finishing it, how do you do that in the onBackPressed event?
即。我想获得尽可能的onPause(),而不是唤起onBack pressed()默认的行为,本质上调用完成()。另一种方式把它的是,我想模仿onUserLeaveHint()?
i.e. I would like to get as far as onPause(), but not evoke the onBackPressed() default behaviour that essentially calls finish(). another way to put it is that i would like to mimic onUserLeaveHint() ?
任何帮助AP preciated!
any help appreciated!
推荐答案
如果你想模仿的具体活动的主页按钮即可做到这一点:
If you want to mimic the "Home" button on specific Activities just do this:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
这将移动工作背景。当您返回,这将是因为它是。
It will move the Task to background.. when you return, it will be as it was.
您可以看到关于这个位置的详细信息:<一href="http://stackoverflow.com/questions/2000102/android-override-back-button-to-act-like-home-button">Android:覆盖后退按钮像home键
You can see more information about this here: Android: Override back button to act like home button
这篇关于onBack pressed隐藏不破坏活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!