I want to get rid of the error which is telling me that there is a
leak in my app because my db gets opened twice. The db doesn't need to
be open the whole time but it is accessed quite often so I don't think
it would be very performant to open and close it for every access.

On 16 Jul., 09:10, YuviDroid <[email protected]> wrote:
> 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 <[email protected]> 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
> > [email protected]<android-beginners%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-beginners?hl=en
>
> --
> YuviDroidhttp://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
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to