Recent

Author Topic: Sqlite insert in thread  (Read 1323 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Sqlite insert in thread
« on: December 17, 2023, 01:07:54 pm »
I can't make jSqliteDataAccess component to work in thread.
I tried using already created component (on some form), but InsertIntoTable crashes app.
Then I tried creating jSqliteDataAccess in thread, but when I call Init, app crashes.

I attached sources which shows my problem.

I am testing with real device (Samsung S23).

Any advice appreciated.

Mongkey

  • Sr. Member
  • ****
  • Posts: 452
Re: Sqlite insert in thread
« Reply #1 on: December 17, 2023, 01:58:44 pm »
Just make sure your db exist, then do request storage permission on every time you open and close db for your safety, android studio would help you much on debuging your app. No need to create thread i think, and i saw your code has no permission request.
« Last Edit: December 17, 2023, 02:05:06 pm by Mongkey »

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Sqlite insert in thread
« Reply #2 on: December 17, 2023, 02:56:41 pm »
Just make sure your db exist, then do request storage permission on every time you open and close db for your safety, android studio would help you much on debuging your app. No need to create thread i think, and i saw your code has no permission request.

Thank you for response.

I tried with threads because I'm inserting large amount of data, so I wanted to have feedback (it lasts minute or two).
Since there isn't Application.ProcessMessages in Android, I thought I could do it in thread.

I solved it using timer and inserting data in chunks.

Zvoni

  • Hero Member
  • *****
  • Posts: 3399
Re: Sqlite insert in thread
« Reply #3 on: December 18, 2023, 08:39:13 am »
Thank you for response.

I tried with threads because I'm inserting large amount of data, so I wanted to have feedback (it lasts minute or two).
Since there isn't Application.ProcessMessages in Android, I thought I could do it in thread.

I solved it using timer and inserting data in chunks.
You do know, that SQLite offers a Callback that some action has taken place?
The only caveat: You are not allowed to use the connection inside that callback, so it should be enough, if you just want to show a progress bar or similiar
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018