0

I have a problem with my database.

Basically my applications read texts and rates of text from my SQLite database and show it on screen. I have also Thread function which downloads content from external internet server and uploads it into the database.

On less popular devices (mostly tablets) it generates errors like:

DB close exception
DB locked 

Someone advised me to create something called a singleton to handle this and I created it but it generates errors. So I have an idea to use AsyncTask instead of Thread; do you think it will help? Maybe you have other solutions?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
James Johnie
  • 11
  • 1
  • 3

3 Answers3

0

AsyncTask will not help you here. You have to create a database connection as a singleton.

Vladimir Mironov
  • 30,514
  • 3
  • 65
  • 62
0

You should get a readable database for when you are reading and a writable database for when you are writing. Then you will be able to do both at the same time.

Both of the methods are in the SQLHelper class

jiduvah
  • 5,108
  • 6
  • 39
  • 55
0

Never close the DB. Make sure you have only one Helper instance per application. See this for reference SQLiteDatabase close() function causing NullPointerException when multiple threads

This may help you :)

Community
  • 1
  • 1
Milind D
  • 314
  • 2
  • 3