Is my way of doing threads in Android correct?

Posted by Charlie on Stack Overflow See other posts from Stack Overflow or by Charlie
Published on 2010-05-17T21:38:30Z Indexed on 2010/05/17 21:40 UTC
Read the original article Hit count: 171

Hi,

I'm writing a live wallpaper, and I'm forking off two separate threads in my main wallpaper service. One updates, and the other draws. I was under the impression that once you call thread.start(), it took care of everything for you, but after some trial and error, it seems that if I want my update and draw threads to keep running, I have to manually keep calling their run() methods? In other words, instead of calling start() on both threads and forgetting, I have to manually set up a delayed handler event that calls thread.run() on both the update and draw threads every 16 milliseconds. Is this the correct way of having a long running thread?

Also, to kill threads, I'm just setting them to be daemons, then nulling them out. Is this method ok? Most examples I see use some sort of join() / interrupt() in a while loop...I don't understand that one...

© Stack Overflow or respective owner

Related posts about android

Related posts about multithreading