tags:

views:

55

answers:

2

Hii everybody ,

I am noob at android and need some help...

I am developing an app which requires me to write to an SQLiteDatabase in one activity and access it from another activity . I am facing a problem implementing this. Any suggestions/ideas as to how we can share the database across multiple activities ...?

+1  A: 

I'd recommend you to use the SQLiteOpenHelper class.

Simply use the same database name consistently across your activities, it should not cause any problem.

SQLiteOpenHelper helper = new SQLiteOpenHelper(
    context, R.string.db_name, null, 1);
SQLiteDatabase db = helper.getWritableDatabase();
SirDarius
A: 

The issue of accessing the same database two different activities can be handled in a few different ways.

The simplest, which should work for your case, is to create a new class that extends SQLITEOpenHelper and instantiate that class from both activities.

Android has no problem with multiple Activities or processes accessing the SQlite database simultaneously.

Brad Hein