views:

87

answers:

2

I've created an Android application which has a certain package name that I've been using personally for months now. I'm about to release it on the market, and I have to change the package name. This cannot be avoided.

My issue is that the application has an SQLite database attached to it that I want to keep, but I know if I change the package name, it'll install as a separate application and I'll have to restart my database, which would take a very long time.

Is there a good way to change a package name while maintaining the SQLite database? Or at least moving the database easily? This will just be for my own phone since it hasn't been released to the public yet.

+2  A: 

Step #1: Add a backup/restore function to your app, that copies the database to/from the SD card. Be sure your SQLiteDatabase and SQLiteOpenHelper objects are closed first.

Step #2: Install a copy of this app, built with the old package, to your phone, and use it to back up your database.

Step #3: Install the production copy of this app to your phone and use it to restore your database.

CommonsWare
This is great, thanks. I found a great piece of example code for that here: http://www.screaming-penguin.com/node/7749. Once the database is imported, is there an easy/simple way to check it's a database that's been saved by that app? In case of importing some invalid file, some random exception would get thrown I would imagine
HXCaine
@HXCaine: "Once the database is imported, is there an easy/simple way to check it's a database that's been saved by that app?" -- you could execute some queries on `sqlite_master` to see if it looks OK, I suppose. http://www.sqlite.org/faq.html#q7
CommonsWare
A: 

For anybody wanting to do the same thing, I've written out how to do backup/import/restore of a database and included a whole class for doing it at this link:

http://hxcaine.wordpress.com/2010/09/14/backing-up-importing-and-restoring-databases-on-android/

HXCaine