1

I am developing an app that for the most part presents large static textual information. I intend the app to be offline so no fetching of data from server. As already discussed on many posts I have following options as per my understanding:

  1. Storing it in XML resource file
  2. text file in assets folder
  3. SQLite database

Though initially I decided to go with XML, but for features like proper sorting, filtering and indexing of data SQLite is handy. I read here, here and here about trade-offs between various methods. Now, if I am storing data in SQLite:

  1. From where should I feed data? Won't I have to first store it in a text file or Strings.xml?
  2. If yes, then I would need to parse XML(may be multiple files) to insert it in database tables

and then reading tables to display data in Views, leading to redundancy (as I could directly populate views after parsing XML) and also taking double the size for data(XML and database). Am sure there is nothing in android studio like "feeding database from some resource while generating apk and not bundle up that resource as a part of apk". So my question essentially is how to effectively use SQLite for large static text data? Thanks
(sorry if my description is bit lengthy than necessary)

EDIT: Also there will be no data manipulation while the app is being used.

Community
  • 1
  • 1
mustafa1993
  • 541
  • 1
  • 5
  • 17

2 Answers2

0

To be clear, your question is more descriptive.. Here is my view on how to solve this problem without redundant processing:

Here are two scenarios to be handled:

Scenario 1: Network available

Step 1: when fetching data from sever, get the data onto an XML. Now create an AsynTask "ParseXML" which will parse the XML.

Step 2: Now, in the postExecute method of "ParseXML" do two things.

One is to store the parsed data onto SQLite database for offline usage.

Second is directly populate the parsed XML data onto your views as you have already mentioned in your question that there is a way for you take the XML data into account and display it.

I believe this way you will be able to save the time of storing the data onto dB and then display.

Scenario 2: Offline display of data when internet unavailable As said by you, query the data from SQLite and display onto your UI.

Also to answer your rest part of your question, you are not wasting the memory, as it is the requirement for you to have offline storage as well and SQLite is the efficient for this kind of storage which requires further processing.

ChaitanyaAtkuri
  • 1,672
  • 11
  • 15
  • Though Scenario 1 seem useful, but as I said I intend app to be offline so I cannot go for it. For Scenario 2, you aptly said its not wasting memory if offline data is app's requirement , so its ok to store data first in resource and store it into DB? – mustafa1993 Jan 14 '17 at 07:07
  • Why cant you use the scenario 1? Could you explain y? Without gettig the data from network – ChaitanyaAtkuri Jan 14 '17 at 08:19
-1

I think you Should use Green DAo It is an open source Android ORM. It is easy to handling data.It is provide facility to access,insert/update and delete data easily.

Read this http://greenrobot.org/greendao/

Shailendra Kushwah
  • 415
  • 1
  • 6
  • 17