我读了很多帖子告诉长操作(如阅读数据库)不应该在主线程上执行。我应该执行插入,删除,更新我自己的SQLite数据库内AsyncTaskLoader
到目前为止,我使用了CursorLoader
(用于“阅读”ContentResolver
)和AsynkTaskLoader
(用于“阅读”我自己的SQLite DB)。
我知道 “的” ContentResolver
执行Insert
,Delete
和Update
我可以使用AsyncQueryHandler
。
我的问题是:在我自己的SQLite数据库上执行Insert
,Delete
和Update
的最佳方法是什么?
我是否应该在AsyncTaskLoader
的方法loadInBackground()
内执行这些操作?
谢谢
使用'AsyncTask'和执行'doInBackground'方法的更新。但是,如果您的更新轻而快速,您可以在UI线程中自由执行它们,让您的生活变得更轻松。 – Dusan
谢谢你:) – MDP
即使是慢速设备也能够每秒执行几百次简单的数据库操作,所以没有必要在后台执行一个或几个操作。 https://stackoverflow.com/questions/28188164/android-sqlite-performance – Dusan