直接代码
// 按返回键的时候返回上一页面不退出,goBack()表示返回webView的上一页面 public boolean onKeyDown(int keyCoder, KeyEvent event) { if(!webView1.canGoBack() ){ exit(); return false; } if ( keyCoder == KeyEvent.KEYCODE_BACK) { webView1.goBack(); exit(); return false; } else{ return super.onKeyDown(keyCoder, event); } } public void exit(){ if (!isExit) { isExit = true; Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); mesHandler.sendEmptyMessageDelayed(0, 2000); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); System.exit(0); } }