Reputation: 9114
I'm struggling to understand the idea behind SQLiteOpenHelper
. It has onCreate()
/onUpdate()
methods which should be overridden, but I don't understand what calls them or when they are called. Will Android call those methods when the app is run at the first time (which doesn't happen in my case), or I should call them manually? I consulted the documentation but couldn't find the answer to my question.
Upvotes: 1
Views: 717
Reputation: 2498
The overriden methods like 'onCreate' are called by the framework when you request a readable and or writable databse (in case it's not created). 'onUpgrade' is useful if you develop the app and change the database version, that's the part where it's called. The framework will take the biggest parts. You'll call the methods from your datasource class. For a longer explanation: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
And a great tutorial: http://www.vogella.com/articles/AndroidSQLite/article.html
Upvotes: 1
Reputation: 68177
They are called automatically at the time when you create the object of class which extends SQLiteOpenHelper
class and request for read/write.
Technically, onCreate
method is called when it detects that the database file is not already available. It is called only once unless you clean the application data. But the onUpdate
is called when ever the version number of your database is found to be incremented.
Upvotes: 2