Android按下back键非退出隐藏到后台

时间:2023-01-18 07:55:56


public boolean onKeyDown(int keyCode, KeyEvent event) {    
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
return true;
}
return super.onKeyDown(keyCode, event);
}


界面重绘

invalidate()或者view.postinvalidate()方法