Java – How to realize a persistent queue on Android

androidjavamobilequeue

My application needs a data structure similar to a queue: put data in it, receive data from it, FIFO-like. With data I mean simple strings for now, later on perhaps more complex objects.
The thing is that the queue and its content should be persistent, regardless of what Android is doing. If the application gets closed and reopened (or even Android reboots), the queue should have the same state and data it had before the application was closed.

I think the queue has to use some kind of storage under the hood, preferably the internal storage of the device. Maybe you could do some brainstorming how to realize this. The queue doesn't necessarily have to run in my application, it could also be some kind of losely coupled background service if that is possible in Android (but private to my application).

Best Answer

May squareup is a good choice.

QueueFile is a lightning-fast, transactional, file-based FIFO. Addition and removal from an instance is an O(1) operation and is atomic. Writes are synchronous; data will be written to disk before an operation returns. The underlying file is structured to survive process and even system crashes and if an I/O exception is thrown during a mutating change, the change is aborted.