Ahh yes, I was confused there for a sec cause I had no way of figuring
out
whether the thread was started or not.

I think this should do the trick.  Thanks again!

On Feb 9, 6:51 pm, Dianne Hackborn <[email protected]> wrote:
> Oh I missed that you are writing your own special Thread.  You probably
> shouldn't use Thread unless you know how to do regular Java synchronization,
> which is what you need to do here.
>
> The framework has a HandlerThread class that does all of this for you.
>
>
>
> On Mon, Feb 9, 2009 at 6:30 PM, JS <[email protected]> wrote:
>
> > Dianne,
>
> > But how do I get the handle?
>
> > My handle is created in run().  From the main thread of control, how
> > do I know
> > when run() finished creating my handle?
>
> > Thanks
>
> > On Feb 9, 6:18 pm, Dianne Hackborn <[email protected]> wrote:
> > > You don't need to know, as long as you can get the Handler you can post
> > > messages to it and the thread will process them in order once it is
> > running.
>
> > > On Mon, Feb 9, 2009 at 5:35 PM, JS <[email protected]> wrote:
>
> > > > I need a message queue in my background thread, so I created a looper
> > > > thread.
>
> > > > // Example 1:
> > > > class LooperThread extends Thread {
> > > >    public Handler mHandler;
>
> > > >    public void run() {
> > > >        Looper.prepare();
>
> > > >        mHandler = new Handler() {
> > > >            public void handleMessage(Message msg) {
> > > >                // process incoming messages here
> > > >            }
> > > >        };
>
> > > >        Looper.loop();
> > > >    }
> > > > }
>
> > > > In my main (UI) thread I do:
>
> > > > LooperThread workerThread = new LooperThread()
> > > > workerThread.start()   // starts initializing the thread
>
> > > > Now the question is how to communicate with it?  I can have an
> > > > accesser getHandle() that returns my handle so I can send messages to
> > > > it.
>
> > > > The issue is that I have no idea when workerThread.start() has
> > > > finishing run() on the thread (and thus initialized the Handler) so I
> > > > have no deterministic way of sending/posting to it just yet.
>
> > > > Another words, I don't know when Looper.loop() starts running...
>
> > > > My goal is to enqueue a message into its MessageQueue immediately
> > > > after Handle is created so it can start handling them.
>
> > > > What's the correct pattern here?
>
> > > > Thanks
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > [email protected]
>
> > > Note: please don't send private questions to me, as I don't have time to
> > > provide private support.  All such questions should be posted on public
> > > forums, where I and others can see and answer them.
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support.  All such questions should be posted on public
> forums, where I and others can see and answer them.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to