Search code examples
androidretrofit2android-storage

How to use cache or local storage?


I am developing an android application using restful webservices. I get all data from server to my app. It always take some time to load the data from server to app activity.How to sync some data to local database and show while app is offline. please help me. Thankyou in Advance.


Solution

  • You can use following ways to store app data:

    1. SQLite : It is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. Hence it is rather easy to use.

    Go through this link from Developer site for reference.

    1. Shared Preferences : SharedPreferences are used to save data based on key-value pair. A preference file is actually a xml file saved in internal memory of device. Every application have some data stored in memory in a directory so whenever getSharedPreferences(String name,int mode) function get called it validates the file that if it exists or it doesn’t then a new xml is created with passed name.

    Go through this link from Developer site for reference.

    1. Internal Storage: This method is specifically for those situations where you need to store data to the device filesystem, but you do not want any other app (even the user) to read this data. Note that this data is deleted from the device when your app is uninstalled.

    Go through this link from Developer site for reference.