Can anyone explain why someone should use the Android Looper feature to create a "pipeline thread" instead of making a normal thread that pulls tasks from a BlockingQueue? On the surface, it seems like two ways to do the same thing.
Android Looper vs BlockingQueue?
Asked Answered
BlockingQueue lets you have multiple consumers and producers whereas the Looper mechanism lets you have multiple producers but only one consumer.
So in Looper thread you only execute one task (runnable) at a time. The looper mechanism was created so you can easily executed runnables (tasks encapsulated as messages) on the UI thread (which runs as a single thread so think of it as a single thread consumer)
Looper/Handler also provide functionality for deferred exection of tasks which BlockingQueue out of the box doesn't. Again this is important in the context of UI toolkits.
© 2022 - 2024 — McMap. All rights reserved.