Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentProvider Threading

Just curious.

getContentResolver().query(...)

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(...)

Thanks!

like image 394
technofunc Avatar asked Mar 06 '12 08:03

technofunc


People also ask

What is the purpose of a ContentProvider?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

Is content provider thread safe?

Conclusion. Although the ContentProvider lacks in thread-safety, often times you will find that no further action is required on your part with respect to preventing potential race conditions.

What is the purpose of the ContentProvider class?

Stay organized with collections Save and categorize content based on your preferences. Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface.

Which process does content provider run?

The content provider normally runs in the UI process thread (which was not open), so in this case of a remote process querying the contentprovider, it would spawn a new instance of the contentprovider upon each query because that separate process (UI thread) was not running at the time.


1 Answers

from Content Provider Basics

Retrieving Data from the Provider

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

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.

like image 123
Mikel Avatar answered Oct 02 '22 18:10

Mikel