开发者

Android and fairly large SQLite datafiles

开发者 https://www.devze.com 2023-02-04 20:13 出处:网络
I\'m starting an Android project, a port from an existing iPhone project I\'ve com开发者_StackOverflowpleted.

I'm starting an Android project, a port from an existing iPhone project I've com开发者_StackOverflowpleted.

I have a fairly large read-only SQLite database, about 100Mb in all. It's called "mydata.sqlite". Where do I place this in my Eclipse workspace? It's too big for "assets".

Next, how do I best get at the file? I would think to try (handling exceptions later) something like:

SQLiteDatabase myDatabase = null;
myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

But I would then need the path string myPath and since I don't know where to put the resource I don't know what this needs to be.

Can I put "mydata.sqlite" into "res/raw" (once I create "raw" in Eclipse?) and then reference it as a resource with "R.raw.mydata"?

I would very much appreciate some direct help here, rather than a reference to a tutorial. I have checked tons of these, including those that are already cited here on stackoverflow. I've also gone through the "Notepad" project in the Android developer documents. However these and the documentation typically consider only new, empty or small databases that aren't always persistent. This should be a simple thing and given the time I've spent already it is perhaps easier to ask.

Thanking you kindly in advance for your assistance.


Note that if you are putting a 100MB asset in your .apk, you are going to end up with an app that is too big to publish on Market.


I've never tried to include such a big DB in my app before.

One solution to your question might be renaming your mydata.sqlite to something like mydata.jpg to avoid the file from being compressed by aapt, which after you can put it in asset folder and access it from there.

Any compressed asset file with an uncompressed size of over 1 MB cannot be read from the APK. [source]

Edit: Seems like your best bet now is to retrieve the data in small chunk off a web server when needed? Found this, check out mjc147's solution and Romain Guy from Google explains about the 1mb limitation.


I did it once with a 35MB SQLite database. What I did:

1.) I used a Windows Tool (I think it was TotalCommander) to split that *.db file into pieces of 1MB.

2.) I've put them in the assets folder.

3.) In my database helper class I moved these pieces together during first startup.

It worked perfect and was fast enough.

What you should think about:

1.) At one point you have 3* 50MB during startup on the internal storage so please consider using SD card for your database.

2.) At one point during update of your apps you have 4* 50MB on your device...

Regards hjw

0

精彩评论

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

关注公众号