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 a database from within an Activity
Android expects you to close it. However this can become very
difficult if you have more than one activity that uses the database,
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 <[email protected]> wrote:
> I think that's an overkill for a simple database.  I thought the main
> reason for a ContentProvider was to make your data available to an
> external entity.
>
> You need to close the database as you cannot pass an open database
> connection between activities, as far as I can tell.
>
> On Jul 23, 6:32 am, Joseph Earl <[email protected]> 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 your database and
> > 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 <[email protected]> wrote:
>
> > > I've seem some conflicting posts on this, so will ask it simply here. Is
> > > it really necessary to close an SQLite database that your activity has
> > > opened (database is 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 the database is
> > > 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to