public class SenseSoccerScoreActivity extends Activity { public boolean onKeyDown(int keyCode, KeyEvent event) { // 如果是返回键,直接返回到桌面 // 经过测试,如果是乐Phone返回桌面会报错 if(keyCode == KeyEvent.KEYCODE_BACK){ // 创建退出系统提示框 if(notSupportKeyCodeBack()){ new AlertDialog.Builder(this) .setMessage(this.getText(R.string.sure_exit_app).toString()) .setPositiveButton(R.string.text_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { exitApp(); // 退出应用处理 } }) .setNegativeButton(R.string.text_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).create().show(); } else { // 返回桌面,经测试,有一些手机不支持,查看 notSupportKeyCodeBack 方法 Intent i= new Intent(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); i.addCategory(Intent.CATEGORY_HOME); startActivity(i); return false; } } return super.onKeyDown(keyCode, event); } // 经过测试,如果是乐Phone返回桌面会报错 private boolean notSupportKeyCodeBack(){ if("3GW100".equals(Build.MODEL) || "3GW101".equals(Build.MODEL) || "3GC101".equals(Build.MODEL)) { return true; } return false; } }