views:

69

answers:

2

I have an app which uses a large amount of data which has been compiled outside the app (on my main PC). The app is for my personal use so there are no complications with having to distribute data updates to other users. However, I am currently following a very convoluted and time-consuming procedure each time I want to update the data, and I wonder if anyone can suggest any ways to streamline it.

The procedure I follow whenever I want to add new data is as follows:

  • I enter the new data into a csv file which I maintain as the source of the relevant table in the database

  • I use SQLite Database Browser to import the data into an existing SQLite database. (This program does not seem to have the ability to append imported data into an existing table, so whenever a table needs updating I have to delete the existing table, then import data from the csv file into a new table, then manually edit the data types for all the fields in the table.)

  • I drag the icon for the database file onto the 'assets' folder of my project in Eclipse.

  • I export the project from Eclipse as an apk file.

  • I copy the apk file to my phone

  • (using Astro File Manager) I uninstall the old version of the app and install the new apk.

  • when the app is run, code based on the example set out here copies the data from the 'assets' folder into the app's data folder; this means that each byte of data takes up two bytes in the phone's internal memory; at present this is not a problem, but could be as the volume of data grows; I wonder if there is a more memory-efficient method?

I should be very grateful for any guidance.

+1  A: 

I don't really know about the database but I do know that if in eclipse you run the app on your phone it will automatically install it. So instead of running it in the emulator when you press the play button, run it on your phone and many of those steps will be eliminated.

To Wipe Database Clean on startup on the emulator:
Click the down arrow next to the play button in eclipse
Select Run Configurations
Click the Target Tab
Check the "Wipe User Data" check box alt text

Mike
Thanks for your very prompt response! Does running the app on the phone direct from Eclipse wipe the existing database from the app's data folder within the phone's internal memory? I have found that when using the emulator I have to manually wipe the data.
Thats a good question. I'm not exactly sure. Like I said I haven't really dealt with any databases in Android. I remember seeing some option to wipe the database when the program runs however. See if you can find some launch options or something like that. I believe there is a check box that you can check to tell it to clean the database.
Mike
Thanks. That is presumably the check box I'm looking for. I wish I knew how to find it!However, I would still be left with all the other tedious steps listed in my original post whenever I want to update the database. Perhaps it would be possible for me to write code within my app to add a menu item to zap an individual table and read in new data from a file on the SD card. There must surely be a way of updating data without going through Eclipse?
Check my edit. I started doing some database stuff and found that.
Mike
Thanks, Mike. Unfortunately, I don't see a "Wipe User Data" checkbox in the Target tab of the Run Configurations dialog. Luckily, this no longer matters as I have found that I can have the database file on the SD card, which simplifies things considerably. See the "Answer" which I'm now going to add to this thread.
I went ahead and added a screen shot in case someone finds this later. I realized it only works on the emulator though and you have to boot up the emulator to get it to wipe anything...so not as useful as I thought.
Mike
Thanks for posting the screen shot, Mike. However, on my PC (Eclipse SDK 3.5.2 running under Windows) there are no check-boxes below Network Latency.
+1  A: 

I have found that I can have the SQLite database on the SD card, which simplifies things for me considerably (and reduces the amount of internal memory occupied by my app.)

The first clue was this blog which told me that it is possible (contrary to the impression I had gained from the Android documentation and from my earlier googling) for an app to refer to a database on the SD card.

I then found this page here on Stack Overflow which points out how simple the code can be.

With the help of the advice on these pages, I now have much simpler DBHelper code in my app where the openDataBase() method simply reads as follows:

public void openDataBase() throws SQLException{
File dbfile = new File(DB_PATH + DB_NAME); myDataBase = SQLiteDatabase.openOrCreateDatabase(dbfile, null); }

There is no longer any need to include the database in my project's "assets", nor therefore to include it in the apk file. And the great advantage is that the database can be updated without having to go anywhere near Eclipse, let alone reinstalling the app.