java - Thread Runnable - stop and resume -


hello i'm new in android(java), , have problem use of thread

i define e new thread timed (every 5 seconds) inside class of android project. "mcontinuethread" variable used cicle every 5 seconds

r = new runnable() {     public void run() {         while (mcontinuethread) {             try {                 thread.sleep(millisec_before_reload);                 mhandler.sendemptymessage(get_tracking);             }             catch (exception e)             {              }         }     } }; t = new thread(r); 

in class there method starttrack() starts thread

public void starttrack() {     mcontinuethread=true;     if (!mthreadisstarted)     {         mthreadisstarted=true;         t.start();     }     else     {      } } 

and there method logout stop thread, using "mcontinuethread" variable:

public void logout() {     //stop thread     mcontinuethread=false;     .... } 

if in class logout() method executed thread stopped, if starttrack() method called again don't know how restart execution of thread.

can me?

you can use asynctask in android. rid of burden of managing threads manually. please visit http://developer.android.com/reference/android/os/asynctask.html


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -