安卓activity捕获返回button关闭应用的方法

安卓activity捕获返回button关闭应用的方法

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  //按下键盘上返回button
  if(keyCode == KeyEvent.KEYCODE_BACK){
   
   new AlertDialog.Builder(this)
   .setIcon(R.drawable.alert_dialog_icon)
   .setTitle("提示")
   .setMessage("是否关闭应用?")
   .setNegativeButton("取消", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {

    }
   })
   .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
     ZhuZhuApp.exit();
    }

   }).show();  
   
   return true;
  }else{  
   return super.onKeyDown(keyCode, event);

  }
 }


安卓activity捕获返回button关闭应用的方法,布布扣,bubuko.com

安卓activity捕获返回button关闭应用的方法

上一篇:Android:使用ViewPager实现左右滑动切换图片(图上有点点)


下一篇:Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现