background - Android: Back key press to stop following activity -


at beginning, apologize bad english.

there problem:

below timer showing message @ every 3 second , when getting out program (using button) message still pop out.

 public runnable mupdatetimetask = new runnable(){                 @override         public void run() {             // todo auto-generated method stub             while (true) {                 try {                     thread.sleep(3000);}                  catch (exception e) {                     // todo: handle exception                 }             mhandler.post(new runnable(){         @override          public void run() {                             toast.maketext(getapplicationcontext(), "testing 3 seconds", toast.length_long).show();                   }               });             }         }  }; 

i use mhandler.removecallbacks(mupdatetimetask); still can't stop it.

thanks in advance.

the call has been made runnable thread class, still active when button pressed. pop messages until application destroys. instead, use this:

    handler.removecallbacksandmessages(null); 

in docs removecallbacksandmessages says. here link: developer website documentation link

"remove pending posts of callbacks , sent messages obj token. if token null, callbacks , messages removed."


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -