Thank you both for your answers. Are you sure using synchronized is enough inside the insert or update? I also got exceptions in call to getReadableDatabase while another thread was being writing so i don't think it would work. I am already using transaction for DB write but it did not seem to make any changes.
The way i do each time i need to read/write/update DB is something like that: OnRead() { db = new myDBHelperClass(); db.getReadableDatabase db.query(...) db.close() } OnWrite() { db = new myDBHelperClass(); db.getWriteableDatabase db.beginTransaction db.insert(...) db.endTransaction } I was rather thinking of using a synchronized in OnRead and OnWrite, but has such methods exists in differents Activities and Task, i am pretty reluctant to do that. I also so design were DB is open in Activity onCreate and closed in onDestroy, but i guess i will not work when a task also needs write in the DB while the DB is open by the activity. 2010/5/9 Evgeny V <evgen...@gmail.com> > I believe you can provide the safe concurrency managment by using DB > transactions. Since you don't care about sequence between separate > activities you can run following snippet: > > try > db.BeginTransaction > db.RunCommand(insert or update etc.) > db.CommitTransaction > catch > db.RollbackTransaction > > Evgeny > > On Sun, May 9, 2010 at 8:18 AM, Senthil ACS <acs....@gmail.com> wrote: > >> For insert() and update(), have it under synchronized blocks. >> >> On May 8, 5:40 pm, Thierry Legras <tleg...@gmail.com> wrote: >> > Hi, >> > >> > I have an application with several tables, each being updated by >> AsyncTask >> > fired by different Activities and used by UI with SimpleCursorAdapter. >> > Though i am not developping a game, I would like to avoid to interrupt >> the >> > user as mush as possible. >> > Has SQLite is not multiaccess proof, what is the best way of handling >> such >> > situation? >> > >> > - I consider adding lock from each DB open and to each close sequence >> but >> > this seems quite subject to bugs >> > - The solution i am using now is that each DB access (read/write) is >> done in >> > UI thread (when AsyncTask completes, DB write is done typically in >> > onPostExecute), but that means user is blocked for several seconds >> during >> > the DB write. >> > >> > Is there any better solution for that? Should i use a ContentProvider? >> when >> > i read "Content providers store and retrieve data and make it accessible >> to >> > all applications", this does not seems to be what i need. Any idea? >> > >> > -- >> > Thierry. >> > (snip) -- Thierry. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en