C
C
ChernovDmitry2014-01-31 14:19:13
Android
ChernovDmitry, 2014-01-31 14:19:13

Android SQLiteOpenHelper and multiple Activities

An Android application has a class that inherits from SQLiteOpenHelper and is responsible for accessing data. The constructor of this class takes a reference to a Context. Do I need to create an instance of this class in each activity working with the database (passing the given Activity as Context) or use, for example, singleton (and what then should be passed to the constructor as Context)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ioooioi, 2014-01-31
@ioooioi

It is possible to construct a single instance with singleton lifetime at application initialization . The Application class is a successor of Context, it is quite possible to use it for your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question