Notice
Recent Posts
Recent Comments
Link
관리 메뉴

설.현.아빠

Back 두번눌러서 종료시키기 본문

안드로이드/Etc.

Back 두번눌러서 종료시키기

설.현.아빠 2011. 10. 4. 14:27



//상단에 선언

 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);
  }
     
    }

Comments