Martin, thanks for your response. The lifecycles of my Activities and
Services are independent from each other. The Service may be writing
to the database while no Activities are active. OTOH, an Activity may
be viewing data while the Service is not running.

So I'm not sure who would be responsible for closing the database; in
my case it is not clear that the Service should do this.

Any other thoughts? Thanks.

On Apr 27, 7:25 am, Martin Obreshkov <[email protected]> wrote:
> I my app i there is service which is working in background and it's holding
> the instance of sql connection. When no activities are using the service
> it's destroyed and the connection is closed.
>
>
>
>
>
> On Tue, Apr 27, 2010 at 2:48 PM, goosedroid <[email protected]> wrote:
> > I have been trying to find a discussion on the best way to handle a
> > common sqlite database which 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 the database when the application terminates?
>
> > Would it be best to extend the android.app.Application class and hook
> > into the onTerminate() to close the database?
>
> > Taking a look at NotePadv3Solution, I can't find where it closes the
> > database - and that is a pretty straightforward example.
>
> > --
> > 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]<android-developers%2Bunsubs 
> > [email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> When I raise my flashing sword, and my hand takes hold on judgment, I will
> take vengeance upon mine enemies, and I will repay those who haze me. Oh,
> Lord, raise me to Thy right hand and count me among Thy saints.
>
> --
> 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