Meng Tim
Meng Tim

Reputation: 438

How to implement a background queue in 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?

Upvotes: 3

Views: 1635

Answers (2)

Piotr Wittchen
Piotr Wittchen

Reputation: 3922

There are probably at least a few ways to solve that problem. You can try to use low-level implementations with Executors and so on, but I'd give an android-job library by Evernote a try.

Upvotes: 1

Robert Nekic
Robert Nekic

Reputation: 3107

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.

Upvotes: 1

Related Questions