Persistent storage - Android offline without internet

I want to fetch data from contentful and show that in my android app, i want that to happen even if there is no internet connection. is it possible to do that with contentful? There is vault, but this will store data only during the lifecycle of app, if the app restarts the data is lost.

There is option in firebase to store and use data in offline mode, like FirebaseDatabase.getInstance().setPersistenceEnabled(true);

what i really need is, i want to store data in cache so that the andorid app can fetch the data and show that info even if there is no internet connect or even if the app restarts.

Thanks in advance for you suggestions…

Have you seen the VaultDatabaseExporter class? Once you’ve used the Sync API to get the contents of a Contentful space, you can use the it to write/update the space to an sqlite database file on the device.

Hello @emilyw,

My name is Mario, I’m the SDKs and Tools developer for Kotlin and Java.

I am curious to see why you are saying that vault only stores it during the lifecycle of the app. It is designed to store the content in an sql database and will persist during closing of the app and even reboots. The only thing it will not survive is removing the app, or clearing the caches.

But other than that, Vault seems to be the tool you are looking for.

Greetings,
Mario

Hi Mario/Charlie,

Thanks for the information, I am looking for options to cache and reuse the response from contentful without using sqldatabase.

Hey,

oh, that sounds rather interesting. If vault doesn’t work for you (Don’t worry: You would not need to write any sql statements) You could always persist the json/parsed responses to a file or, if the responses are reasonable small, you could think of using shared preferences.

May I ask for your use case and why sqlite seems out of the question? Maybe there is yet another avenue to explore?

Hey,

Thanks again the information, the Use case : need to store all contentful content responce locally in the mobile app, so that the app will work without internet connection.

Does vault works with REALM? ( GENERAL QUESTION)

Hey,

sadly realm is not supported out of the box.

It is possible to write a middleware, doing the same thing Vault does, just using Realm: You would need to sync all the data from Contentful, parse them into realm data objects, ensure the linking between realm objects is the same as the linking between Contentful resources, and then save them in the REALM realm.

That said: This is a not easy feat to be done right, especially since a solution for your use case already exists, just using a different database technology.

Hey,

Thanks for the information, will do accordingly

1 Like