fadedbee
fadedbee

Reputation: 44807

What is the correct, efficient way for threads to communicate under Android?

What is the correct, efficient, way for threads (within a service) to communicate under Android?

I have looked at Intents (serialization overhead), HandlerThreads and Loopers (bundling overheads).

A receiving thread should have have (synchronized) queue(s) to which objects (of types known at compile time) can be added.

I have previously written such functionality for JavaME, but I was under the impression that Android would have a "standard" efficient way of communicating between threads, using compile-time-known types.

Am I missing something fundamental? (I do not have much recent Java experience beyond JavaME/1.3.)

Upvotes: 0

Views: 72

Answers (2)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52956

The native way to send messages to a thread is Handler's. If that doesn't meet your requirements (which are?), you can implement a thread messaging system yourself using Java primitives and/or java.util.concurrent classes.

Upvotes: 1

sdabet
sdabet

Reputation: 18670

How about using Handlers and MessageQueues ?

Upvotes: 0

Related Questions