1

I made an SQlite Database with my SQLiteHelperClass. After it was created first time, i pulled it from the data/data/../databases Folder, edited it(I added Content) and pushed it again into the Data Folder. I used DDMS to pull and push the Database. Now my App can access all the Data in my DB. But just with my Emulator! When i run the app with my Device i cannot access the Database.. The App seems just to create a new empty Database. So I think the Data/Data/../Databases Folder on my Device is empty..

Why is the Database that I created by my Emulator deleted, if i upload the App on my Device? How is it possible that the App works absolutely fine on my Emulator, but not on my App.

I'm sorry, English is not my native language. I don't think that any code would be helpfull, cause of the problem seems to be a logical..

Kara
  • 6,115
  • 16
  • 50
  • 57
  • If you manually updated and pushed the db back onto the emulator, it will not be automatically included with the apk to be installed on the device. You'll need to put the db into your `res/assets` folder and then in the app take it from there and copy to your `data/data` – Aleks G Jun 27 '12 at 15:17

3 Answers3

0

in order to create your DB you can use the SQLiteOpenHelper class.

http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

Stefano Ortisi
  • 5,288
  • 3
  • 33
  • 41
0

If you want to create a pre-loaded DB outside of your app and use it in your app later, you will have to put it in your assets directory and then copy it to your apps databases directory the first time your app is started.

This is due to the fact that as a security measure, on real (unrooted) devices nothing but your own app is allowed access to their data directory (which contains the databases directory).

There is a good tutorial for creating/copying your own DB outside of the app and copying it to the apps databases directory here.

Barak
  • 16,318
  • 9
  • 52
  • 84
0

You can use a pre-populated database. Keep it in Assets folder & then copy it to proper location data\data\your packagename\database.

Prepopulated database - complete example is here.

Community
  • 1
  • 1
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149