I have a singleton class that creates a connection to a Sqlite db and runs queries. I need to pull the database stuff out of the Singleton and create a database handler class. My question is: Does the database handler class also need to be a Singleton? Thanks.
-
@user552447 did it help? your problem is solved? if yes please accept an answer. – Beasly Jan 26 '11 at 16:45
2 Answers
Probably not, you could have a class that is instantiated normally every time and used like every other class, I do not write singleton data layers since long time and not even static classes for it any more.

- 43,984
- 10
- 98
- 147
Actually you don't need to write your own singleton. You just need to have a class which inherits from SQLiteOpenHelper
Later in the code you just need to use: SQLiteDatabase db = helper.getWritableDatabase();
The SQLiteOpenHelper cares if the D already exists. If yes, it gives to the DB as readable or writeable database. If no DB is available it creates one... like this you don't have to check if the DB is already created.
You can see here a full example i posted some days ago...
Android - Sqlite database method undefined fot type
Hope this helps :)