0

I have created three activities. one is DBActivity which is used to performing the database oriented operation(creating, inserting, retreiving, droping closing etc.). The createing the database is executing in the constructor of the DBActivity. The seconding activity StoreActivity will store the EditText values to the database. The third activity RetrieveActivity will retreive the database values. I have created the object for the DBActivity and saved the values in to the database. While retreiving the database in the RetreiveActivity, What is the idea to get the database..? If I created the object for the DBActivity a new database will created, it led me to the trouble. How can I access the same database created in the StoreActivity...Can you help me with codings..? Thanks in advance....

1 Answer 1

1

Your Question reflects the problem in your concept. You want to access the database independent from all your activities. So you should not put your database logic in a class of type Activity. Write your own database helper class by subclassing from this one: SQLiteOpenHelper.
Now you can create an instance of that database helper class in every Activity you want to access your database. And you can maybe think about to try a Singleton instance. So you always retrieve the same helper instance.

Edit: The key for retrieving always the same database is, to always use the same database name in the constructor of the SQLiteOpenHelper class.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.