"Do you mean a new connection to the database for each activity? "
Yes.
How many activities do you expect to have active (i.e. in a state
between onCreate and onDestroy)?

If this number is very large, then a singleton that manages such a
connection can be the best thing to do.

But if this number is relatively small, just keep it easy and open a
connection in each onCreate and close it in onDestroy.

Don't worry about onDestroy not being called. If onDestroy is not
called, your process will be killed, closing all connections
automatically.


On Mar 23, 12:52 pm, westmeadboy <[email protected]> wrote:
> Do you mean a new connection to the database for each activity?
>
> With my model, the database connection is lazily opened but only once.
> Essentially, the database is opened the first time an activity is
> created in that VM.
>
> I don't want to tie the lifecycle of the database connection to
> activities, but rather to the application/VM itself.
>
> On Mar 23, 5:24 pm, Streets Of Boston <[email protected]> wrote:
>
>
>
> > What if you just close the connection to the database in the
> > onDestroy?
> > If the total number of connnections reaches 0, doesn't the database
> > eventually shut-down?
>
> > On Mar 23, 7:39 am, westmeadboy <[email protected]> wrote:
>
> > > On Mar 11, 8:38 am, westmeadboy <[email protected]> wrote:
>
> > > > In Activity1.onDestroy() I close the database. However, is this a good
> > > > approach? Is it not possible that Activity1 is killed but Activity2
> > > > stays alive? If so, then Activity2's db calls will suddenly fail.
>
> > > Would be great if someone knows the answer to this?
>
> > > I would rather close the database when the application (i.e. task?) is
> > > terminated, but I don't know the proper place to make such a call.- 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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to