开发者

big sqlite database in android application

开发者 https://www.devze.com 2023-01-29 19:17 出处:网络
I am t开发者_C百科rying to build dictionary app(actually it is a modification of google SearchableDictionary sample), whose source of words and their definitions is very big, around 5MB. I tried many

I am t开发者_C百科rying to build dictionary app(actually it is a modification of google SearchableDictionary sample), whose source of words and their definitions is very big, around 5MB. I tried many ways and using many formats and it still cant run properly on android. Sqlite database should be the best solution, I have built it and its size is 10MB(tried building it both before runtime and during runtime). The main problem is the size of the definitions, but I have seen some other applications have managed to do this. It might be that there are some file size limits built into android system, but anyways if they werent it all takes so much to search and run queries in this sqlite database.

What am I doing wrong? BTW: It HAS to be offline dictionary (download definitions max 1 time).

Problem in a nutshell:

word -definition 
word2 -definition2...

Stored in a 10MB sqlite database (tried loading it from assets), not working. With some hacks (loading it manually with eclipse DDMS tool) it is working but terribly slow.


Are you loading the database from the Assets folder? If yes, then that's your problem. There is a file size limit on what is in the assets folder (1mb I believe).

You have two options:

  1. Split up your database into multiple 1mb files
  2. Create a webservice. Have your application call the webservice which in turn downloads the database to your Android device. OR create a webservice API that your application uses to get data on as it needs it basis.


I have achieved by zipping the database and unzipping it into external caching direcotry (SD Card). you can look at the sample code here - http://www.android.manutech.mobi/2011/03/how-to-manage-sqlite-databases-with.html


Rename it to something like "databasename.mp3" or any media format. It won't be compressed by the package manager and therefore you can use it just like you need.


Have you tried compressing the file? If the data is just raw text I bet it'll compress to smaller than 1 MB.


1) Store a compressed version of only the words using the GZIP. (this will be very small only about 350k, and must be pre-sorted)

2) Load the list into a:

new ArrayList<String>();

3) Use a binarySearch to find the word

.binarySearch

4) When you need a definition, call an API like this with the word

http://services.aonaware.com//DictService/DictService.asmx/Define?word=aardvark

5) parse the resulting XML


10M file is just way too small to worry about. It didn't work, it might be because of the way of opening the database file. By default, Android read database file from ://data/data/PACKAGENAME/databases/DATABASENAME.

A simple solution could be: 1) compress the db file to res/raw/DATABASE.zip, 2) then unzip it to //data/data/PACKAGENAME/databases/.

You can get sqlite android demo code from here: http://www.cs.dartmouth.edu/~campbell/cs65/lecture15/lecture15.html

0

精彩评论

暂无评论...
验证码 换一张
取 消