-1

I've created an SQL database programatically with the default way of extending SQLiteOpenHelper and overriding onCreate. The database is created successfully on the device, and I can insert and retrieve data from it.

Now I need to submit the application to the store. The thing is I need to move the database to assets so it can be loaded to every device containing the application. I have tried the use avd pull to retrieve the database from the device and place it in the assets but data folder retrieved is empty. I cannot recreate the database each time the application is loaded for it takes much time.

halfer
  • 19,824
  • 17
  • 99
  • 186
coder
  • 5,200
  • 3
  • 20
  • 45
  • once you have the db in the assets, you need to copy it to the data/data//databases/ folder at first boot – njzk2 Dec 21 '12 at 09:56
  • I currently have it on device, and I want to move it to my assets, how can I do that? – coder Dec 21 '12 at 10:08
  • 1
    http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an-android-application/9109728#9109728 – Yaqub Ahmad Dec 27 '12 at 12:38
  • thank you for the link, I was able to copy the database to my assets and now every time I load the application to a new device I load the database. I used the sd to copy the database to pc then to assets. thank you for your contribution. :) – coder Dec 27 '12 at 13:01
  • Please do not revert good edits, Coder. We do not permit an insistence on case/spelling errors and begging messages here. – halfer Nov 16 '19 at 18:42

1 Answers1

1

follow the steps below,

1)fire the following query on your databse,

Select * from my table;

2)retrive the rows result by above query.

3)convert your retrieved data into Json using Gson.

4)create simple text file and save your json to that file.

5)put this file to asset folder.

6) now clear your database,remove Gson library,remove the query above.

7) Next time,when you start your application load the text file (which is containing json response) from assets parse it using json library and insert row one by one into your database table.

8)do the step 7 only first time when user starts the application.

This is not the perfect answer but you can try this.

dd619
  • 5,910
  • 8
  • 35
  • 60
  • I'm afraid step 7 is so time consuming, I already have the content of the database in a text file but I cannot do step 7 each time a new user loads the application, it will take no less than 7 min, the dictionary content is very big – coder Dec 21 '12 at 10:12
  • what about doing it in background thread or handler or async task? – dd619 Dec 21 '12 at 10:13
  • it will slow down the performance dramatically, when I first did it on the device, the screen just went black until the database was created then it came back to life – coder Dec 21 '12 at 10:15