恰好被传递到的onCreate()方法SQLiteDatabase对象是什么?对象、方法、onCreate、SQLiteDatabase

2023-09-07 16:45:47 作者:软糖

前几天我正经历着这是通过调用引起db.close()错误在的onCreate()方法。

A few days ago i was experiencing an error which was caused by a call to db.close() inside the onCreate() method.

一些更多的人有类似的问题,这是在这里解决:Cannot创建Android的SQLite数据库:PRAGMA错误

Some more people had similar problems and this was solved here: Cannot create Android SQLite database: PRAGMA error

我现在为什么发生这种情况很感兴趣。我搜索了Android的源一段时间,但我找不到其中的onCreate()方法被称为点,或这方面有任何文件,以找出发生了什么 SQLiteDatabase 呼叫周围code到对象的onCreate()

I am now really interested in WHY this is happening. I searched some time in the android sources but i couldn't find the spot where the onCreate() method is called or any documentation about this to find out what happens to the SQLiteDatabase object in the surrounding code of the call to onCreate().

有谁知道更多关于此?或者知道哪里读来了解更多关于此? : - )

Does anyone knows more about this? Or knows where to read to get to know more about this? :-)

推荐答案

最后,我发现了一个code段这说明了什么我正经历:

Finally i found a code snippet which explains what i was experiencing:

int version = db.getVersion();
        if (version != mNewVersion) {
            db.beginTransaction();
            try {
                if (version == 0) {
                    onCreate(db);
                } else {
                    onUpgrade(db, version, mNewVersion);
                }
                db.setVersion(mNewVersion);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

        onOpen(db);
        success = true;
        return db;

这是code段出了Android源。你可以从中看到,有很多事情发生aroung的onCreate()和onUpgrade()。所以,一切被周围code管理。你(一种奇怪的自言自语....的)只需要在乎做你的数据相关的东西的分贝。创新,交易,和关闭由code围绕着它进行处理。

this is one code snippet out of the android sources. And you can see from it, that there are many things happen aroung onCreate() and onUpgrade(). So everything is managed by the surrounding code. You (kind of weird talking to myself....) only have to care about doing your DATA related stuff on the db. Creation, Transaction, and closing is handled by the code surrounding it.