1

I'm new to programing for android and i'm still learning. So I have a question about the location of the SQLite database. Is it stored in the same file system as the application ? And also i'm not sure can the database be created before the app is installed(can it come with the app) or can the database only be created from inside the app ?

And what if i wanted my app to come with a database that already has tables and records which is local and not on a server. Would that be possible ?

tdxius
  • 281
  • 3
  • 11

2 Answers2

0

Database is created after the app installation or after the db changes. The db is stored in /data/data/your_package/databases/

be4code
  • 688
  • 4
  • 15
0

SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration.

You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.

Access to an SQLite database involves accessing the filesystem. This can be slow. Therefore it is recommended to perform database operations asynchronously, for example inside the AsyncTask class.

If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME.

The parts of the above directory are constructed based on the following rules. DATA is the path which the Environment.getDataDirectory() method returns. APP_NAME is your application name. FILENAME is the name you specify in your application code for the database.

You can also follow this tutorial for further understanding.

http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Jaffar Ramay
  • 1,147
  • 8
  • 13
  • Kindly don't forget to ACCEPT the answer if it clarified your questions. – Jaffar Ramay Aug 05 '13 at 20:44
  • But what if i wanted my app to come with a database that already has tables and records which is local and not on a server. Would that be possible ? – tdxius Aug 05 '13 at 20:57
  • Basically you precreate your database, put it in your assets directory in your apk, and on first use copy to "/data/data/YOUR_PACKAGE/databases/" directory for further reading http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ – Jaffar Ramay Aug 05 '13 at 21:58
  • Kindly don't forget to ACCEPT the answer if it clarified your questions. – Jaffar Ramay Aug 05 '13 at 21:59