传递给 onCreate() 方法的 SQLiteDatabase 对象会发生什么?
几天前,我遇到了一个错误,该错误是由 onCreate()
方法内调用 db.close()
引起的。
还有一些人遇到了类似的问题,这里解决了: 无法创建Android SQLite 数据库:PRAGMA 错误
我现在真的很感兴趣为什么会发生这种情况。我在 android 源代码中搜索了一段时间,但找不到调用 onCreate()
方法的位置或任何有关此的文档来了解 SQLiteDatabase
发生了什么> 调用 onCreate()
的周围代码中的对象。
有谁对此了解更多吗?或者知道在哪里阅读以了解更多相关信息? :-)
A few days ago i was experiencing an error which was caused by a call to db.close()
inside the onCreate()
method.
Some more people had similar problems and this was solved here: Cannot create Android SQLite database: PRAGMA error
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? :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我找到了一个代码片段,它解释了我所经历的事情:
这是 Android 源代码中的一个代码片段。从中你可以看到,onCreate() 和 onUpgrade() 周围发生了很多事情。所以一切都由周围的代码管理。你(对自己说话有点奇怪......)只需要关心在数据库上做与数据相关的事情。创建、事务和关闭由其周围的代码处理。
Finally i found a code snippet which explains what i was experiencing:
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.