ContentProvider线程化

ContentProvider线程化

本文介绍了ContentProvider线程化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很好奇.

getContentResolver().query(...)

我知道加载程序在后台线程上运行查询.这也适用于插入,更新和删除吗?我应该为此类调用创建AsyncTasks,Threads等吗?较大的更新可能会阻塞我的应用程序的主线程.

I know that Loaders run queries on background threads. Does this also apply to inserts, updates and deletes? Should I create AsyncTasks, Threads, etc... for these kinds of calls?Large updates might block my application's main thread.

getContentResolver().insert(...)

谢谢!

推荐答案

来自内容提供商基础

本节介绍如何使用 以用户词典提供者为例.

This section describes how to retrieve data from a provider, using the User Dictionary Provider as an example.

为清楚起见,本节中的代码段调用 在实际代码中, 您应该在单独的线程上异步进行查询.一种方法 这样做是使用CursorLoader类,更多信息中将对此进行介绍. 详细信息请参见《装载机指南》.另外,代码行是片段 只要;他们没有显示完整的申请.

For the sake of clarity, the code snippets in this section call ContentResolver.query() on the "UI thread"". In actual code, however, you should do queries asynchronously on a separate thread. One way to do this is to use the CursorLoader class, which is described in more detail in the Loaders guide. Also, the lines of code are snippets only; they don't show a complete application.

这篇关于ContentProvider线程化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:11