gpt4 book ai didi

android - Android应用应该在哪里调用SQLite getWritableDatabase?

转载 作者:IT王子 更新时间:2023-10-29 06:21:50 26 4
gpt4 key购买 nike

文档位于 http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase%28%29状态:

Database upgrade may take a long time, you should not call this method [getWritableDatabase] from the application main thread, including from ContentProvider.onCreate().

这引出了一个问题:为了获得最佳实践,应该从哪里调用 getWritableDatabase?

我的感觉是,也许它应该在应用程序启动时调用一次,并通过回调将数据库标记为就绪。这是正确的吗?

最佳答案

对于小型和灵活的数据库,我想这不是什么大问题。

否则,我会使用从 onCreate 调用的永远很棒的 AsyncTask

关于android - Android应用应该在哪里调用SQLite getWritableDatabase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4640039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com