I have a class:
public class DbAdapter {
private DbHelper dbHelper;
private SQLiteDatabase db;
private final Context context;
...
}
and i want have it available in all activities. The class provides access to my sqlite database.
What is the most elegant and neat way to do it? I thought about creating object in each activity (it should “connect” me to the same database, right?).
You can achieve it extending the Application class. Google has this to say about it:
I have done it myself like this:
Then you just access it calling getApplicationContext.getDatabase()