android - how can i add multiple click on back pressed button -


how can add multiple backpressed button when press button show me press double click exit after toast message when click double on press button app exit... did method twice exit app want implement 3 times

    if (doublebacktoexitpressedonce){         super.onbackpressed();         doublebacktoexitpressedonce = false;      }      else {         doublebacktoexitpressedonce = true;         toast.maketext(this, "double press exit", toast.length_short).show();     } 

i suggest way:

    int counter = 0;       ....      public void onbackpressed() {                         counter++;                         if(counter > 2){                             system.exit(0);                         }else{                             toast.maketext(this, "triple click exit!", toast.length_short).show();                           }                          final long delay_time = 3000l;                         new thread(new runnable() {                             public void run(){                                 try {                                     thread.sleep(delay_time);                                     counter = 0;                                 } catch (interruptedexception e) {                                     e.printstacktrace();                                 }                             }                         }).start(); } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -