Android上SQLite的最佳做法是什么?

不羁岁月 提交于 2020-05-03 19:36:19

问题:

What would be considered the best practices when executing queries on an SQLite database within an Android app? 在Android应用程序中对SQLite数据库执行查询时,最佳做法是什么?

Is it safe to run inserts, deletes and select queries from an AsyncTask's doInBackground? 从AsyncTask的doInBackground运行插入,删除和选择查询是否安全? Or should I use the UI Thread? 或者我应该使用UI线程? I suppose that database queries can be "heavy" and should not use the UI thread as it can lock up the app - resulting in an Application Not Responding (ANR). 我认为数据库查询可能“很重”,不应该使用UI线程,因为它可以锁定应用程序 - 导致应用程序无响应 (ANR)。

If I have several AsyncTasks, should they share a connection or should they open a connection each? 如果我有几个AsyncTasks,他们应该共享一个连接还是应该分别打开一个连接?

Are there any best practices for these scenarios? 这些方案是否有最佳实践?


解决方案:

参考一: https://stackoom.com/question/ASd1/Android上SQLite的最佳做法是什么
参考二: https://oldbug.net/q/ASd1/What-are-the-best-practices-for-SQLite-on-Android
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!