Hello All! The suggestion seems to be that using a ContentProvider, you would open the database once and then simply use that single open database. However, this isn't what any of the samples do!
For example, the NotePad sample, in its ContentProvider (ie. NotePadProvider.java) it opens a SQLiteDatabase via mOpenHelper.getWritableDatabase() or mOpenHelper.getReadableDatabase() at the top of every function but doesn't close it. Since I followed this example with my ContentProvider, this is also what I did in my code. I didn't even know that there *was* a SQLiteDatabase.close() method until I was watching "adb logcat" and saw tons of exceptions like this and decided to investigate: E/Database( 1480): java.lang.IllegalStateException: /data/data/ com.bibliobird.android.reader/databases/lingwo.db SQLiteDatabase created and never closed So, the question remains: Is it really necessary to close a SQLiteDatabase? For the fun of it, I attempted modifying my ContentProvider to close all SQLiteDatabase's before returning and it causes all my query()'s to get Cursor's with no data in them. So, that's not good! Should I just ignore this exception from "adb logcat"? It doesn't seem to cause any problems... ?? Regards, David Snopek. On Jul 23, 1:25 pm, Joseph Earl <joseph.w.e...@gmail.com> wrote: > 1) You can restrict access to your ContentProvider to only your > application or suite of applications by setting the authority > 2) I thought it was overkill myself when first reading about it. > However after following this pattern I must say its much neater > (especially when loading cursors in threads) and had the handy side > effect getting rid of any errors about closing/opening databases I > had. > > From what I can tell, when you open adatabasefrom within an Activity > Android expects you tocloseit. However this can become very > difficult if you have more than one activity that uses thedatabase, > especially if you need to perform re-queries every time onResume is > called to update the data. > > On Jul 23, 1:29 am, Zsolt Vasvari <zvasv...@gmail.com> wrote: > > > I think that's an overkill for a simpledatabase. I thought the main > > reason for a ContentProvider was to make your data available to an > > external entity. > > > You need toclosethedatabaseas you cannot pass an opendatabase > > connection between activities, as far as I can tell. > > > On Jul 23, 6:32 am, Joseph Earl <joseph.w.e...@gmail.com> wrote: > > > > I agree it's not well documented what to do when opening/closing the > > > DB from within an activity. > > > > Instead implement a ContentProvider which opens yourdatabaseand > > > provides access to it. > > > Your activities will then never need to worry about opening/closing > > > the DB. > > > > On Jul 22, 3:54 pm, Doug Gordon <gordo...@gmail.com> wrote: > > > > > I've seem some conflicting posts on this, so will ask it simply here. Is > > > > it really necessary tocloseanSQLitedatabasethat your activity has > > > > opened (databaseis in local memory or on SD card)? > > > > > I would think it would be good practice, but I noticed that the Android > > > > samples such as the Notepad tutorial and SearchableDictionary sample do > > > > not do this. I've also seen sample code where thedatabaseis > > > > consistently opened, read from, and closed, but that would seem to add > > > > unnecessary overhead. > > > > > Doug Gordon > > > > GHCS Systems- Hide quoted text - > > > > - Show quoted text - -- 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