22.02.2011 19:39, ydm пишет:
Thank you, Kostya, but I'm not sure a singleton, which holds a
reference to the first activity's context, wouldn't cause memory
leaks. The best solution I found so far is to use the Application
object as context for the database object.

It definitely would - that's why I wrote:

>  If you're not going to implement a private content provider (which is
>  one way), I'd use a simple singleton, keeping a reference to one and
>  only SQLiteOpenHelper subclass object,_*initialized with the application
>  context*_.

I was suggesting something like:

class DatabaseThing {
    public static DatabaseThing get(Context context) {
        if (gInstance == null) {
// Get the application context, so we can keep a reference to it gInstance = new DatabaseThing(_*context.getApplicationContext()*_);
        }
        return gInstance;
    }

    // Private implementation constructor
    private DatabaseThing(Context context) {
    {
        ...
    }

    private static DatabaseThing gInstance;
}

-- Kostya

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
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