how do i create the database in my android app?

前端 未结 2 1954
再見小時候
再見小時候 2021-01-16 23:32

I\'m trying to use SQLite in my android app. I\'ve created the helper class like this:

public class EventoSQLHelper {

    // Configuração da base(nome e ver         


        
2条回答
  •  忘掉有多难
    2021-01-16 23:36

    Well, let's quote the Docs:

    A helper class to manage database creation and version management.

    You create a subclass implementing onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and optionally onOpen(SQLiteDatabase), and this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary. Transactions are used to make sure the database is always in a sensible state.

    So what this means is, that you don't have to explicity create the "database-file" it's done for you by the SQLiteOpenHelper. So the first time you're opening your Database it will be created. (It will automatically run through onCreate in your DataBaseHelper)

提交回复
热议问题