我使用此代碼,打開新的活動onBackPressed方法的onkeydown不正常
View view = getLocalActivityManager().startActivity("recently_viewd",
new Intent(context,Job_Description.class)
.putExtra("line", result)
.putExtra("limit",0)
.putExtra("Alert", false)
.putExtra("str_Descrption",edit_Jobdesc.getText().toString().trim())
.putExtra("str_location", edit_JobLoc.getText().toString().trim()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(view);
而且在Job_Description.class我要處理的Android返回鍵。 我重寫Job_Description.class上的OnBackPressed()方法,但它不起作用。
@Override
public void onBackPressed() {
super.onBackPressed();
Toast.makeText(this, "BAck Click", Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(context, Tab_Bar.class));
return;
}
之後,我實現OnKeyDown()方法,但它也不工作。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
Toast.makeText(this, "BAck Click", Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(context, Tab_Bar.class));
return true;
}
return super.onKeyDown(keyCode, event);
}
請幫我我如何處理返回按鈕 在此先感謝。