Yes, that sounds right.

I generally tie an instance to the lifecycle of the class that uses it.

That assures that it is only open as long as it's needed and that it's
closed when it isn't.

Larry


On Fri, Mar 8, 2013 at 4:16 AM, Saurav <[email protected]>wrote:

> Thanks Mark, you have always been a charm!
> Thanks Larry, that was new info.
>
>
> So, what I take from your answers is that I can open a (Helper) connection
> at start of the application and close it at the application close, using
> the same connection for getting Readable and Writable db instances?
>
> And maintain different instance of Helper (each) for every service (cos
> they keep running, irrespective of the visible app, DUH!)?
>
> Please correct me if I am wrong.
>
> Thanks again!
>
>
>
>
>
> Regards,
> Saurav Mukherjee.
>
> Twitter <https://twitter.com/#!/fasuke>
> Facebook <https://www.facebook.com/fuusuke>
>
>
> On Thu, Mar 7, 2013 at 8:52 PM, Larry Meadors <[email protected]>wrote:
>
>> Just be careful closing the database - if you have multiple threads
>> sharing an instance of a single SQLiteOpenHelper, the SQLiteDatabase
>> mDatabase isn't like a jdbc connection pool.
>>
>> If you close it fron one thread, it's closed for real.
>>
>> ...and of course, if you don't close it, it whines.
>>
>> Larry
>>
>>
>> On Thu, Mar 7, 2013 at 8:07 AM, Mark Murphy <[email protected]>
>> wrote:
>> > On Thu, Mar 7, 2013 at 9:54 AM, Saurav <[email protected]>
>> wrote:
>> >> How many SQLiteOpenHelper instances should be created? Should there be
>> just
>> >> one and should it be reused?
>> >
>> > Ideally, yes, particularly if you are planning on accessing the
>> > database from multiple threads. One SQLiteOpenHelper instance means
>> > one SQLiteDatabase instance, and SQLiteDatabase is designed to manage
>> > operations from multiple threads.
>> >
>> > --
>> > Mark Murphy (a Commons Guy)
>> > http://commonsware.com | http://github.com/commonsguy
>> > http://commonsware.com/blog | http://twitter.com/commonsguy
>> >
>> > _The Busy Coder's Guide to Android Development_ Version 4.6 Available!
>> >
>> > --
>> > --
>> > 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
>> > ---
>> > You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to [email protected].
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>>
>> --
>> --
>> 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
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Android Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to