Brian, Thanks for your response. However as mentioned in the OP, all activities and services are in the same application. From what I understand, ContentProvider is for exposing and consuming data outside of your application, but this is not my scenario.
On Apr 27, 11:34 am, Brion Emde <[email protected]> wrote: > There is a standard way of doing this in Android: ContentProvider. It > is so important that there is a whole chapter written about it in the > Developer's > Guide:http://developer.android.com/guide/topics/providers/content-providers... > > Also, look at the Notepad example, as others have suggested. It > implements a very simple ContentProvider and shows how you can use it. > > On Apr 27, 5:48 am, 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] > > 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

