János János - 2 months ago 21
Java Question

How to create serial queue in Android?

In iOS I can create GCD serial queue like this:

let serialQueue = DispatchQueue(label: "serialQueue")


Blocks are executed in a FIFO order, one block at a time. How can I do it in Android?

This is how chunk of code can be performed on the queue:

serialQueue.async {


As I see
AsyncTask
is serial: "Starting with HONEYCOMB, tasks are executed on a single thread to avoid common application errors caused by parallel execution."

I guess t is FIFO, the execution.

Found this JAVA 8 concurrency tutorial.

Answer

Use Executor.newSingleThreadExecutor(). You can pass a Runnable or Callable<V> that represents the work to be done.