0

In my android app a list view contain so much data (Approx 1832 items) using webservices . I wanted to get the data from server once in a day and use that data without calling webservice . Is it possible to store that data in cache or somewhere else and represent it for whole day.

  • use sqlite db.... – Divyesh Patel Apr 15 '17 at 11:00
  • yes it is best! – Jaydeep Devda Apr 15 '17 at 11:01
  • Is there any other way instead of Sqlite.? –  Apr 15 '17 at 11:02
  • depends on data size, may sharedPreferences is one of option – Jaydeep Devda Apr 15 '17 at 11:04
  • You will get the data as text i think. Just save that text to file. – greenapps Apr 15 '17 at 11:04
  • You coulde tell me which httpclient you are using, and enable its cache...so that api call would not be made the next time it fetches it :) – yUdoDis Apr 15 '17 at 11:28
  • If you are getting the response in the JSON format , simply store the JSON response in SharedPreferences . Now when user navigates to the page then check if JSON data exists in the preferences , if exists parse that data and display in the list view . One thing to be noted to check day changes , store a date too in the shared preferences so that you can identify that day has changed , now you needs get data from server . – Shishupal Shakya Apr 15 '17 at 11:43

1 Answers1

0

SQ lite is the best solution for persistent data storage, for simplicity of usage you can use libraries such as db flow enter link description here , realm enter link description here

Also make use of job scheduler API (API level 21) or alarm manager for performing web service calls..

Ramees Thattarath
  • 1,093
  • 11
  • 19
  • 1
    Using SQLite to store server response is not light weight task , It requires lot of code to store and to fetch data again from SQLite DB , Instead using SharedPreferences requires few lines of code to store and fetch data again . – Shishupal Shakya Apr 15 '17 at 11:48
  • But what if i have bundles of data to store .? Is that a proper way to store it on sharedPreference? @AndroidDev –  Apr 15 '17 at 12:02
  • In the question you are saying that you are getting data from web service , so your web service is returning data in the format of bundles ? – Shishupal Shakya Apr 15 '17 at 12:06
  • 1
    Nonsense. You receive text. And you extract strings from them which you put in the items of a listview. Or better yet you put those strings in an array which you then offer to an adapter for your listview. – greenapps Apr 15 '17 at 12:14
  • But what if i have bundles of data to store .? Here what do you mean by bundles ? From where you got these bundles ? – Shishupal Shakya Apr 15 '17 at 12:14