//상단에 선언

 private boolean isTwoClickBack = false;
.

.

@Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  if(event.getAction() == KeyEvent.ACTION_DOWN){
   if(keyCode == KeyEvent.KEYCODE_BACK){
    if(!isTwoClickBack){
     Toast.makeText(this, "'뒤로'버튼을 한번더 클릭 하시면 종료됩니다." , Toast.LENGTH_SHORT).show();

     CntTimer timer = new CntTimer(2000, 1);
     timer.start();
    }else{
     finish();
     return true;
    }
    
   }
  }
  return false;
 }

.

class CntTimer extends CountDownTimer{

  public CntTimer(long millisInFuture, long countDownInterval) {
   super(millisInFuture, countDownInterval);
   isTwoClickBack = true;
  }

  @Override
  public void onFinish() {
   // TODO Auto-generated method stub
   isTwoClickBack = false;
  }

  @Override
  public void onTick(long millisUntilFinished) {
   // TODO Auto-generated method stub
   Log.i("Test"," isTwoClickBack " + isTwoClickBack);
  }
     
    }

저작자 표시 비영리 변경 금지
신고
Posted by DoDo4989

댓글을 달아 주세요