KaliMa KaliMa - 2 years ago 88
Java Question

How to correctly perform SQL queries in background thread?

I have a

that has one of the pages containing a
which is populated from the SQLite database. This
is filled by first grabbing a
and then extracting all the various fields into objects that I then add to the

However I have also read that I should be performing SQL operations in another thread as to not make the entire app lag.

What is the correct way to do this? My SQLite class is implemented as a singleton so it suffices to call
when I need access.

Answer Source

SQL background queries should be handled like any other background action. You can use e.g. Threads or AsyncTasks to perform them.

Thread example

public void performActionAsync(){
    new Thread(new Runnable(){
        public void run(){

private void performAction(){
    //perform actions as normal
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download