AMerle
AMerle

Reputation: 4354

Same DB for multiple devices

I need to make my app faster at first launch. For the moment I use a JSON file that I parse and I insert data in a db at first launch. The problem is this can take long long time (Samsung spica :/) because there is a big amount of data.

I was thinking about another way to do it. I would have 2 apps, one which generate the first sqlite db, which I copy into the resources of my main app. Therefore, I don't need anymore to embed my JSON file but my db instead. I know this is possible and I know how to do it.

The question is: Can the DB be different depending on the device or android API version ? If I copy this db, every device will have the exact copy, so is this a problem, is there a risk for the db to not be compatible with X device / API version (I'm also talking about some constructors who like to make some changes) ?

Thank you for your time.

Upvotes: 3

Views: 331

Answers (5)

Chandrashekhar
Chandrashekhar

Reputation: 498

i dont think it will make any major difference if u r using sqlite 3.0 which is the minimum version used in all devices. But if u r using features of SQLite version 3.6.19 like foreign key etc they will not work in devices running version 3.0 .

Upvotes: 1

Drusantia
Drusantia

Reputation: 327

I have a project that does the following: - on start (or pressing a refresh button) it checks on a wcf service for new data (4 tables, about 1600-2000 table entries sum). - The service generates cvs files for each table and compresses the data (gzip) - The android application downloads the compressed file and extracts the data in it - After that, it processes the csv files The whole thing takes about 2 seconds (including download) on an older device (1 core, 1GHz).

I suggest You, to use a service for your task to do the work for You in the background, and if I were You, I'd use cvs instead of JSON since JSON (as far as i know) slower to work with when you have lots of data.

Running the information-processing and inserting to the database in a service has some important advantages: - If the user presses the home key, the service can continue the work in the background - You can still show the user a progress dialog to let him/her know that your app is working - android makes it possible, to run a service on a different process, so if your main application is entirely killed (by the user or by the system when need memory for something else), so this way you still can do your db stuff. - disadvantages of running in a different process are - that's another vm so it consumes more memory - can cause problems on db access, but since you would use it only to fill the database on the first run, it's ok You can read more about this here(android:process): http://developer.android.com/guide/topics/manifest/service-element.html#proc

Summary - use cvs instead of json - use service to fill the database - in the app check if all rows are in place before do anything if you use a different process service (select count(*) from your table and check if it matches the number of expected rows in db).

Upvotes: 0

M.A.Murali
M.A.Murali

Reputation: 10158

I have an idea to do faster processing but the following criteria should meet your requirement

1) is your database static?

2) or it is dynamic, modify your db for modified row.

if your db is dynamic, first preload the db with app and update your db when changes occur in the server.

i think it may help you.

Upvotes: 0

souleymane sidibé
souleymane sidibé

Reputation: 506

if the data don't change you can just use an xml file(or json) that contain all your data. And at the first launch, use AsyncTask for populate your sqlite database.

Upvotes: 0

rciovati
rciovati

Reputation: 28073

You may want to use some features that are introduced in "newer" version of SQLite. For example foreign key support has been introduced in SQLite version 3.6.19 (API Level 8, Froyo) but triggers, afaik, are supported in all versions of Android.

So if in your database there are foreign key contraints they won't work on android with API level <8.

I don't think there are other differences.

Upvotes: 2

Related Questions