[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-06 Thread hackbod
If you are using HandlerThread, use HandlerThread.getLooper().quit(). If you are using a raw Thread, you should implement some protocol to tell the thread to stop itself. Generally HandlerThread is a lot easier for this kind of stuff, since it takes care of all of these various details for you.

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-04 Thread Jo
HI, I got a simple solution for this after some trials. instead of creating/starting a new thread for every button click, I started a thread that listens for button clicks. But, can I use thread.stop in onDestroy() to kill the thread. Thanks, --Jo On Oct 4, 1:52 pm, Jo <[EMAIL PROTECTED]> wro

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-04 Thread Jo
also May I know what is the difference between handlerthread.getid and handlerthread.getThreadId. In my application this thread will be created and started everytime a button is clicked(for sending chat message). so I printed handlerthread.getid and handlerthread.getThreadId. I get incremented v

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-04 Thread Jo
THanks Justin, I would like to use the HandlerThread as it sounds simple compared to regular threads. can somebody post a template for using HandlerThread with android.os.Handler and runnable. final Handler mHandler2 = new Handler(); HandlerThread android_thread_send; // Create runnable

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread Justin (Google Employee)
Someone pointed out that the runThread member should be declared as volatile or the behavior of this code is unpredictable. Cheers, Justin Android Team @ Google On Oct 3, 4:58 pm, "Justin (Google Employee)" <[EMAIL PROTECTED]> wrote: > Jo, > > Sounds like HandlerThread is almost certainly the wa

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread Justin (Google Employee)
Jo, Sounds like HandlerThread is almost certainly the way you want to go here, but you can do a similar thing with a regular thread, using a public member to control it. You should stop the the thread in onPause or onStop depending on what its doing. public class DummyActivity extends Activity {

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread Jo
OK Hackbod you are taking about quitting handlerThread. Got it. I thought it was normal java.lang.thread. Thanks, --Jyothsna On Oct 3, 3:32 pm, Jo <[EMAIL PROTECTED]> wrote: > HI Hackbod, > > 1) Thanks about the suggestion. I never used HandlerThread. Maybe I > can take a look. > > 2)coming to t

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread Jo
HI Hackbod, 1) Thanks about the suggestion. I never used HandlerThread. Maybe I can take a look. 2)coming to the other suggestion.How can I quit a thread. I mean which method should I use because thread.resume/suspend/stop are all deprecated. HI Joe, I am using a separate daemon thread for rece

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread Joe Erickson
This almost sounds like it should be a Service. The thread will only run when you're Activity is running (basically) and isn't guaranteed to be kept around once the Activity is cleaned up. You may want a Service running that can handle this and then you'll have much more control over it. Will y

[android-developers] Re: How many threads can be created or how to avoid thread leak

2008-10-03 Thread hackbod
Just use HandlerThread to have a single thread sitting there processing messages that you send to it. Even better, create the thread in onStart() and quit it in onStop(). On Oct 2, 9:49 pm, Jo <[EMAIL PROTECTED]> wrote: > HI, > > I am developing a chat application. Everytime a user clicks a butt