N
N
Nikita Sklyuev2012-07-01 11:45:23
Java
Nikita Sklyuev, 2012-07-01 11:45:23

How to work with sqlite from multiple threads in android?

Hello dear hackers.
I am writing out of desperation.
I am developing an application that writes data to the database in several threads.
When a second vustream is attached for writing or reading, an error occurs that some cursor has not been closed.
Please tell me how to work with sqlite in android with several threads.
Maybe someone has experience of circumventing this problem
I would be very grateful for any help.
PS I know how sqlite works, and I know that opening a file for writing is blocked, I'm interested in how to create a queue or something like that

Answer the question

In order to leave comments, you need to log in

6 answer(s)
K
Konstantin, 2012-07-01
@trilodi

Make yourself a class xxxApplication extends Application, write it in the manifest.
And in it make one connection to the database. There is only one Application class in the android program, so all variables are there as singleton.

S
Sergey, 2012-07-01
Protko @Fesor

I'm not much of an Android expert, but I think you should read up on thread synchronization and POSIX.

M
m08pvv, 2012-07-01
@m08pvv

How many streams are planned? Maybe it's better to make a thread that works with the base, and the rest access it?

M
m08pvv, 2012-07-01
@m08pvv

Stackoverflow discussion

G
gleb_kudr, 2012-07-01
@gleb_kudr

I would make an adapter that sucks data from different streams into itself and organizes a queue. And communication with a DB would conduct only by means of this adapter.

I
ilichme, 2012-07-03
@ilichme

In android, the database can be opened either from several threads for reading, or from one for writing. sad bat true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question