백버튼 두번 눌러 앱종료하기
2초 이내에 백버튼을 2번 누르면 앱이 종료된다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //앱종료시간체크 long backKeyPressedTime; //앱종료 위한 백버튼 누른시간 ... //뒤로가기 2번하면 앱종료 @Override public void onBackPressed() { //1번째 백버튼 클릭 if(System.currentTimeMillis()>backKeyPressedTime+2000){ backKeyPressedTime = System.currentTimeMillis(); Toast.makeText(this, getString(R.string.APP_CLOSE_BACK_BUTTON), Toast.LENGTH_SHORT).show(); } //2번째 백버튼 클릭 (종료) else{ AppFinish(); } } //앱종료 public void AppFinish(){ finish(); System.exit(0); android.os.Process.killProcess(android.os.Process.myPid()); } | cs |
* 첫번째 백버튼을 누른 시간을 변수에 넣은 후 2000초 이내에 두번째 백버튼을 클릭했는지 체크하여 2초이내에 2번 백버튼을 눌렀으면 앱을 종료합니다
'IT > Ⅱ. Android' 카테고리의 다른 글
Android canvas 에서 속이 빈 도형 그리기 (0) | 2018.07.21 |
---|---|
Android 액티비티를 팝업(Popup)으로 띄우기 , 데이터 주고받기 (6) | 2018.07.14 |
Android 에러 No static field xxx of type I in class Lcom/xxx/xxx/xxx/R$id (0) | 2018.07.07 |
Android 에러 Program type already present: xxx.xxx.xxx.BuildConfig (0) | 2018.06.30 |
Android 화면 캡처막기 (0) | 2018.06.27 |