一、重写返回按钮
//2024-12-02
@Override
public void onBackPressed() {// 在这里添加您的拦截逻辑// Toast.makeText(this, "返回键被拦截", Toast.LENGTH_SHORT).show();// super.onBackPressed();showExitDialog();
}
二、弹出提示
private void showExitDialog() {AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("屏触科技").setMessage("是否退出客户端?").setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 点击确定按钮,不做任何操作Cyber_Public_Var.m_cpu.onDestroy();// 在这里添加退出应用的相关代码android.os.Process.killProcess(android.os.Process.myPid());}});AlertDialog dialog = builder.create();dialog.show();}