Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a background queue in android?

Tags:

android

I want to implement a background queue. It works as: when user click a button, add a task (this task need time to be done) to the queue, queue should run on the background thread. If user click button again, add another task in the queue. The background thread runs the tasks in the queue one by one until the queue is empty. I want it only be 1 background thread working on the task. What kind of android feature I can use? or is there any example?

like image 511
Meng Tim Avatar asked Mar 09 '26 09:03

Meng Tim


1 Answers

Check out using AsyncTask with a SingleThreadExecuter.

http://developer.android.com/reference/java/util/concurrent/Executors.html#newSingleThreadExecutor()

Creates an Executor that uses a single worker thread operating off an unbounded queue.

like image 87
Robert Nekic Avatar answered Mar 12 '26 01:03

Robert Nekic