Hi Alok,

I instantiated my DBAdapter class (presumably your "core layer") from the
(singleton?) class extending android.app.Application:

public class MyApplication extends Application {

    private DbAdapter dbAdapter;

    /**
     * @return dbAdapter, already opened
     */
    public DbAdapter getDbAdapter() {
    if (dbAdapter == null) {
        dbAdapter = new DbAdapter(this);
        dbAdapter.open();
    }
    return dbAdapter;
    }

    @Override
    public void onTerminate() {
    Log.d(TAG, "Calling onTerminate...");
    if (dbAdapter != null)
        dbAdapter.close();
    dbAdapter = null;
    super.onTerminate();
    }

}

I'd be curious to hear what others think. I have occasionally seen sqlite
errors that I havn't root caused, but I can't think why this would be a bad
approach.  Any Activity needing a db connection can get it from this
instance, which should be available throughout the app's lifetime.

Steve

On Sun, Dec 20, 2009 at 9:15 AM, Alok Kulkarni <[email protected]> wrote:

> Hi guys,
>
> I have a database with 5 tables in it.There is a core layer which
> communicates with the database and fetches the results and stores them in
> memory temporarily.
> Now my UI layer wishes to display the data retrieved by core layer in the
> UI.
> What i want to have ideally is to create an object of the core class and
> call the DB operations whenever i want.The class which creates this core
> object does not extend activity , but from examples i see , i need to pass
> the activity as a context parameter to SQLiteOpenHelper.What context shd i
> pass in that case ? There is also some concept of AsyncTask in Android but i
> havent yet chkd how to use it.. Please help me on this one.. Thanks..Alok.
>
> --
> 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]<android-developers%[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 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