1

I need to keep data like provinces and towns in it, in a DB. How do I do it?

JaseemAmeer
  • 107
  • 2
  • 15

3 Answers3

2

if your list does not need to be changed and its fixed, then instead of involving database, I would recommend you to use string-array in your resource file to save the list

waqaslam
  • 67,549
  • 16
  • 165
  • 178
0

If access to an resource array is not efficient enough and if you have a large amount of data you might want to consider this kind of solution: Create an empty database in code and provide an activity which responds to an intent with this action: android.intent.action.SEND. Respond by parsing the sent file and populate the database with the contents. Design a format which can be easily parsed (XML is not needed for everything ;-) so the code to parse the file and fill the database is small (my binary for this including an UI to show progress (which is the larger part of the activity) is less than 12 kB in size).

The file may be distributed separately (extra apk, download, whatever). The benefit of this approach is that you do not need to store your initial database content within the apk and thus the data is only stored once on the device (after the file has been deleted). Otherwise you have the data in the database plus the source code or asset in the apk.

Further possibilities are given as answers to this question: Android database approach for future updates

Community
  • 1
  • 1
Stefan
  • 4,645
  • 1
  • 19
  • 35
0

You can also use a pre-populated database, keep it in assests folder like explained here.

Community
  • 1
  • 1
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149