0

Handler in Android uses a MessageQueue to access the stored messages. Using a Bound Service the clients send messages, which are queued, and handled by the Handler. This creates a problem that the handler is able to handle only one message at a time. While this is OK for one-way messages, when the clients are expecting a reply, they receive it after a while. This creates problems as large number of messages are queued in, which take a lot of time.

  1. If a Service wanted to handle multiple requests at a time, how could that be done?
  2. Can multiple Handlers attach to the same MessageQueue and handle multiple requests?
  3. Related to this, what in general, is the rule to receive reply from the
coolharsh55
  • 1,179
  • 4
  • 12
  • 27
  • ad 1 use threads, ad 2 yes, many Handlers can be assigned to a Looper/MessageQueue – pskink Jul 05 '14 at 14:02
  • could you provide more info about how threads can be used? – coolharsh55 Jul 05 '14 at 14:04
  • btw if using bound Services use IBinder interface to call two way transaction – pskink Jul 05 '14 at 14:07
  • http://docs.oracle.com/javase/tutorial/essential/concurrency/ – pskink Jul 05 '14 at 14:08
  • @pskink Bound Services are bound using IBinder interfaces, the question is about handling multiple messages simultaneously. And while I do know about concurrency and threading mechanisms, a link to Oracle Java is NOT helpful to understand how these threads are used in a service to handle multiple requests. All the same, thank you. – coolharsh55 Jul 05 '14 at 14:23
  • pass a Messenger to your Service then Service spawns a Thread for each incoming Message and when complete calls Messenger.send – pskink Jul 05 '14 at 15:12
  • http://stackoverflow.com/questions/5193913/handlers-messagequeue-looper-do-they-all-run-on-the-ui-thread create separate thread/looper/message que for your higher priority messages and they will not block on other message/que/handler traffic that u may have for lower priority messages – Robert Rowntree Jul 05 '14 at 17:29

0 Answers0