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
Post a Comment