本文介绍了onBack pressed不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些功能的问题。我想重写本机背按钮,但是功能永远不会得到所谓的,我不明白的地方它是错误的。
公共布尔的onkeydown(INT键code,KeyEvent的事件)
{
如果((键code == KeyEvent.KEY code_BACK))
{//返回键pressed
mCountDownTimer.cancel();
在意向=新意图(getApplicationContext(),MyActivity2.class);
startActivity(在);
mCountDownTimer.cancel(); 返回true;
}
返回super.onKeyDown(键code,事件);
}公共无效onBack pressed()
{
mCountDownTimer.cancel();
在意向=新意图(getApplicationContext(),MyActivity2.class);
startActivity(在); 返回;
} // onBack pressed结束
解决方案
试试这个:
@覆盖
公共无效onBack pressed(){
mCountDownTimer.cancel();
在意向=新意图(这一点,MyActivity2.class);
startActivity(在); super.onBack pressed();} // onBack pressed结束
I have a problem with these functions. I want to override the native back button, but the functions never get called and I don't understand where it's the mistake.
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{ //Back key pressed
mCountDownTimer.cancel();
Intent in = new Intent(getApplicationContext(), MyActivity2.class);
startActivity(in);
mCountDownTimer.cancel();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed()
{
mCountDownTimer.cancel();
Intent in = new Intent(getApplicationContext(), MyActivity2.class);
startActivity(in);
return;
}// end of onBackpressed
解决方案
Try this:
@Override
public void onBackPressed(){
mCountDownTimer.cancel();
Intent in = new Intent(this, MyActivity2.class);
startActivity(in);
super.onBackPressed();
}// end of onBackpressed
这篇关于onBack pressed不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!