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
--~--~---------~--~----~------------~-------~--~----~
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