简体   繁体   中英

Android: ContentProvider Request in AsyncTask get delayed when some other ContentProvider operations/sqlite writes are happening

I have a ContentProvider access in a AsyncTask which generally works fine while looking up some data stored in sqlite on the phone.

However I also have some other background services that do network checks and download and update some data.

It is observed that this network related background activity is affecting my ContentProvider. The ContentProvider which entirely works on offline data either delays the response or just never returns for a long time.

Are then any locking/queuing mechanisms on the ContentProvider or the sqlite database? The writes do not happen to the same tables as the reads.

Are then any locking/queuing mechanisms on the ContentProvider or the sqlite database? The writes do not happen to the same tables as the reads.

  1. ContentProvider implementations require additional synchronization to be thread-safe, ie the developer is in charge of it

  2. SQLite is synchronized, ie writes exclude reads

In your case you might want to enable write-ahead-logging (WAL) , api 11+. This enables writes to happen in a separate journal in parallel: holding the lock and excluding parallel reads is not necessary anymore.

See for instance:

SQLite, Content Providers, & Thread Safety

Official docs for SQLite locking

Good explanation of WAL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM