0

I am writing my handlers in two different activities which are running on the same UI thread. Now the question is if I post a message using these two different handlers, would it end up in the same message queue associated with the main thread or each handler has a separate message queue associated with it.

Any pointers will be appreciated.

2 Answers 2

1

You should look at this Handler

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. MessageQueue is associated with the thread. But what happends in case of multiple handlers. So if I post a message on one handler, then will the handleMessage of both the handlers will be called ?
Hm :) interesting, I think yes but I'd write a simple app and try it, I think it's the best way to figure it out. UPD: I suppose it implements observer pattern, may be I'm wrong, if so it will notify each handler about message.
1

Each Handler is associated with a Looper. A Looper is in turn associated with a Thread.

So if you have a single thread, you'll have a single message queue.

Check this link for a nice introduction to Loopers & Handlers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.