MadProgrammer
MadProgrammer

Reputation: 453

How to implement a persistent queue in Android

I would like to implement a persistent queue in Android. Essentially a queue where data is stored until another thread takes it and sends it somewhere. The order in which data is stored or consumed is not important (ex. FIFO, LIFO, LILO, etc). Is there a modern library in Android that supports this?

I found a previous question on SOF but this dates from 2012: How to realize a persistent queue on Android

Upvotes: 1

Views: 3591

Answers (2)

Flood2d
Flood2d

Reputation: 1358

There are a lot of way to do this. You can persist the collection by saving it into a database like SQLite, serialize it as a file and deserialize it when you need it, or you can save it in SharedPreferences of Android.

Anyway there is a cool library called Hawk (https://github.com/orhanobut/hawk) that is a

Secure, simple key-value storage for android

How Hawk works: Hawk mechanism

If you take a look at the Hawk source code you can see that it uses SharedPreferences to save data to the disk. It serializes the object you want to persist and saves it into SharedPreferences as a String.

Quotes and images are taken from Hawk github page.

You can find other alternatives here (in the "Persistence" section) : https://github.com/codepath/android_guides/wiki/Must-Have-Libraries

Upvotes: 3

arsent
arsent

Reputation: 7183

You can check out Priority Jobqueue

It has an option to persist the jobs and prioritise them.

Upvotes: 1

Related Questions