views:

129

answers:

1

I'm toying with the Android SDK, with a view to writting a simple app for friends (and maybe for sale).

This app will search a database for keywords and dispaly the results on the screen, I've had a look at the searchabul dictonary and the notepad demo applications, but I'm still a bit unsure some things.

I know I need to write a class that extends the SQLiteOpenHelper, and use that to create the database, however how do I check if the database already exists?

Does onCreate get called on installation or every time an instance of the class is created? is the easyist way just to try and add the database each time and catch any errors (feels a little dangerous to be makeing the assumption every error will be due to the database already existing).

Thanks in Advance.

+2  A: 

Your SQLiteOpenHelper will handle the creation of the database. Once the db has been created on the users phone SQliteHelper will be happy until you change the database version number.

As long as you put your db creation code in the onCreate method of a SQLiteOpenHelper you will be fine.

Have a look at the onUpgrade method from the Notepad demo as you need to write some code that handles what happens when your db tries to upgrade itself (it will do this when you change the db version number)

disretrospect
Thanks, that's what I hoped... onCreate sounded a little too much like just a bog standard constructor (yes even through I've seen constructors in Android Java as well). Also thanks for the tip about onUpdate, again I saw that in the notpad demo and thought it's what it did but wasn't sure.P.S. I agree about the question title... I just couldn't think of a better one :)
Scott Herbert