我已经覆盖了我的活动中的OnBackPressed
函数,但它没有被调用。在其他活动上它工作正常。
这是我的方法:
@Override
public void onBackPressed() {
Log.e("back",""+1);
UserPage.getstate().finish();
Intent i=new Intent(CreateGroup.this,UserPage.class);
i.putExtra("title11","dd");
startActivity(i);
finish();
}
此方法未被调用,每次按后退按钮时都会调用默认的OnBackPresssed
。
答案 0 :(得分:8)
试试此代码
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("back",""+1);
UserPage.getstate().finish();
Intent i=new Intent(CreateGroup.this,UserPage.class);
i.putExtra("title11","dd");
startActivity(i);
finish();
}
return true;
}
答案 1 :(得分:7)
有类似的问题。对我来说问题是我重写了隐藏KEYCODE_BACK keydown事件的onKeyDown()。
答案 2 :(得分:4)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back pressed.
return true;
}
return super.onKeyDown(keyCode, event);
}
答案 3 :(得分:2)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("back",""+1);
UserPage.getstate().finish();
Intent i=new Intent(CreateGroup.this,UserPage.class);
i.putExtra("title11","dd");
startActivity(i);
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}