mmm I'm not really sure what you are trying to achieve. Exactly, at what times do you want to open/close the db? The db should stay open while your application is running? So, even when you switch among activities (yours activities)?
On Thu, Jul 15, 2010 at 6:36 PM, Bender <abende...@googlemail.com> wrote: > @YuviDroid > > I'm trying the following at the moment: the open() only gets called in > both onCreate() methods with: > > mDb = new DbAdapter(this); > if(mDb.getDatabase() == null || !mDb.getDatabase().isOpen()) { > mDb.open(); > } > > The problem I'm having with this is, that there is always a new > DbAdapter created which is fine when the activity is created the first > time. But this way "mDb.getDatabase() == null" will be always true > because its a new mDb. > > So I either need to find a way to check if the database is opened > without "mDb" or need to remember mDb even if the activity is stopped. > > @Kostya Vasilyev > > I tried that, but then my app crashes while switching between > activities. When I was searching for the error I put logs in the > open() and close() methods by my DbAdapter and I could see the > following: > > * open() (app, activity1 started) > * open() (i hit a button in activity1, activity2 is starting and > open is called within onStart) > * close() (activity1 is stopped, in onStop close is called) > > When I go back to activity1 it throws an exception because the > database is closed. -.- > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- YuviDroid http://android.yuvalsharon.net -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en