I'm not sure if you guys have looked into reference counting, but that
sounds like a possible solution to me. If you use a static reference
count in your database helper object, your close method can only close
the connection if there's just one reference left. I'm actually still
working through this issue myself, but that sounds like it could fix
some people's problems.

On Apr 29, 7:32 am, Federico Paolinelli <[email protected]> wrote:
> Just putting a "dbstatus" flag in the dbhelper class.
> When open() is called, I check the flag to see if the db is already
> open, if so I do nothing, otherwise I do the open stuff and then I set
> the flag.
>
>
>
>
>
> On Thu, Apr 29, 2010 at 2:26 PM, gcstang <[email protected]> wrote:
> > As am I, I'm doing the same with onPause/onResume.
>
> > Federico how are you checking if yourdatabaseconnection is open?
>
> > On Apr 28, 3:18 am, Federico Paolinelli <[email protected]> wrote:
> >> An sqllitedb (helper) object for each activity (but the open one is
> >> only in the active activity). Every time an activity closes or pauses,
> >> I call the close() method.
> >> However, I am interested in any more elegant and standard solution of
> >> this problem.
>
> >> Federico
>
> >> On 27 Apr, 21:49, goosedroid <[email protected]> wrote:
>
> >> > Frederico, were yousharingthe same SQLiteDatabase instance object
> >> > between all activities via some singletonhelperclass, or was each
> >> > Activity instantiating a new SQLiteDatabase object?
>
> >> > On Apr 27, 8:58 am, Federico Paolinelli <[email protected]> wrote:
>
> >> > > On 27 Apr, 13:48, goosedroid <[email protected]> wrote:
>
> >> > > > I have been trying to find a discussion on the best way to handle a
> >> > > > common sqlitedatabasewhich is shared by multiple Activities (or
> >> > > > multiple Activities and Services). This is all in the same
> >> > > > application.
>
> >> > > > It seems that if each Activity has:
>
> >> > > > void onCreate()
> >> > > > {
> >> > > >     SQLiteDatabase db = SQLiteDatabase.openDatabase(...)
> >> > > >     ...
>
> >> > > > }
>
> >> > > > void onDestroy()
> >> > > > {
> >> > > >    db.close();
> >> > > >    ...
>
> >> > > > }
>
> >> > > > this would be wasteful, assuming there would be N SQLiteDatabase
> >> > > > objects with N activities that needed access to the same db.
>
> >> > > > One could go about making a singleton, but who would be responsible
> >> > > > for closing thedatabasewhen the application terminates?
>
> >> > > > Would it be best to extend the android.app.Application class and hook
> >> > > > into the onTerminate() to close thedatabase?
>
> >> > > > Taking a look at NotePadv3Solution, I can't find where it closes the
> >> > > >database- and that is a pretty straightforward example.
>
> >> > > > --
>
> >> > > What I did (which may not be the best solution is to call the
> >> > > db.close() in onPause() method and call the db.open() in any
> >> > > onResume() method of all activities.
> >> > > Be aware that during the activity creation both onCreate() and
> >> > > onResume() methods are called, so you need to check the db is not
> >> > > opened yet.
>
> >> > > Hope this helps,
>
> >> > >     Federico
>
> >> > > --
> >> > > 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 
> >> > > athttp://groups.google.com/group/android-developers?hl=en
>
> >> > --
> >> > 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 
> >> > athttp://groups.google.com/group/android-developers?hl=en
>
> >> --
> >> 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 
> >> athttp://groups.google.com/group/android-developers?hl=en
>
> > --
> > 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
>
> --
> --------
> Federico
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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