android中关于tabhost的返回键处理方法 onkeydown事件无效

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		// TODO Auto-generated method stub
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){  
			if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {   

				if(System.currentTimeMillis() - exitTime > 2000){
					Toast.makeText(this, "再按一次返回键退出", Toast.LENGTH_SHORT).show();
					exitTime = System.currentTimeMillis();
					return false;
				}
				else{
					MyApplication application = (MyApplication) getApplication();
					application.finishAllContext();
					System.exit(0);
				}
			}  
			return true;  
		}  
		return super.dispatchKeyEvent(event);
	}

你可能感兴趣的:(android中关于tabhost的返回键处理方法 onkeydown事件无效)