Android documentation says
ContentProvider methods can be called from various ContentResolver objects in different processes and threads, they must be implemented in a thread-safe manner
And I found this post on Stackoverflow A开发者_如何学Cndroid - sqlite content providers and multithreading which says it's thread safe already ??
So, Just wondering how to create a thread-safe ContentProvider
? Is it enough if I make the insert/update/delete methods syncronized
public synchronized Uri insert (Uri uri, ContentValues values) {
}
You could make every method synchronized
, but make sure it is absolutely necessary before you do. In cases where the underlying data source is already thread-safe making the methods synchronized
could be costly. See my blog post on this topic for more information.
精彩评论