[android-developers] Preferred mechanism for shared access to a Sqllite database.
My initial version of my app used sqlite databases directly, opening
and closing on create/destroy. However, I received occasional crashes
with the message "database is locked". I looked into it, and found
that sqlite databases really only can handle one writer at a time. I
had converted my service to be alarmManager fired, which resulted in a
service spawned thread interacting with the database along with the
UI.
I've converted to a contentProvider model of database access to see if
this would help centralize my data access. The data is all private,
and all but one table would make any sense to anyone else.
I have a few questions:
1) Does Android create a singleton instance of the contentProvider on
the phone? If its used externally, I assume there is just the single
instance in my app process.
2) Are accesses to the content provider done in a means not requiring
synchronization? If I have a UI performing queries while a service is
performing updates, will I run into any database locked errors? The
database accesses inside the provider will be done transactionally, so
I'm not worried about partial reads.
3) Is a contentProvider overkill for this? Would a properly
synchronized singleton provide the same safety from locked databases
without the overhead? Is there much overhead for content providers?
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home