• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads, Looper, Handler and Message Loops

 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[I would be vague in my description of the problem as my knowlege in this area is limited. Please excuse.]

I was reading up on Threads in Android and wanted to know about how inter-thread communication happens over message loops, in general.

In Android, when Looper.prepare() is called inside run method of any thread, a message queue is initialized for that thread. Other threads, can post messages to this queue. To handle these messages, a handler needs to be bound to the message queue. The Handler(class) will have callbacks which would be invoked whenever appropriate messages are posted in the thread's message queue.

Is this a standard way/mechanism for inter-thread communication?

Any links etc. that discuss this topic are appreciated.

Thanks.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this helps: http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monu Tripathi wrote:
Is this a standard way/mechanism for inter-thread communication?



Having a single thread which processes messages from a queue is a very standard approach to inter-thread communications. It basically is how the Swing's event handling works. The Android Looper/Handler paradigm makes it a little easier to make your own message processing thread, but isn't terribly different than, for example, a single threaded use of the ExecutorService API in Java 5+.


Any links etc. that discuss this topic are appreciated.



Someone asked about the Looper/Handler a little while ago. Here is my attempt at showing what the code might be like: Looper/Handler in Android
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:Maybe this helps: http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/


Thanks for the link Lester!

Steve Luke wrote:Someone asked about the Looper/Handler a little while ago. Here is my attempt at showing what the code might be like: Looper/Handler in Android


very cool!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic