Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. @Override
  2. public boolean onKeyDown(int keyCode, KeyEvent event) {
  3. if(keyCode == KeyEvent.KEYCODE_BACK)
  4. {
  5. exitBy2Click();
  6. }
  7. return false;
  8. }
  9.  
  10. private static Boolean isExit = false;
  11.  
  12. private void exitBy2Click() {
  13. Timer tExit = null;
  14. if (!isExit) {
  15. isExit = true;
  16. Toast.makeText(this, "click again to quit", Toast.LENGTH_SHORT).show();
  17. tExit = new Timer();
  18. tExit.schedule(new TimerTask() {
  19. @Override
  20. public void run() {
  21. isExit = false;
  22. }
  23. }, 2000);
  24.  
  25. } else {
  26. finish();
  27. System.exit(0);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement