Should I excute Insert, Delete, Update on my own SQLite DB inside AsyncTaskLoader Should I excute Insert, Delete, Update on my own SQLite DB inside AsyncTaskLoader sqlite sqlite

Should I excute Insert, Delete, Update on my own SQLite DB inside AsyncTaskLoader


If your queries are simple and it won't make much time to execute then simply you can use it in main thread itself.

If you're doing big data process then you have two options.

  1. AsyncTask:

If you want to update your UI after an operation, you can use AsyncTask to do the process in a background thread and pass the result into the main thread. for more info about AsyncTaksk click here.

2.Thread

If there is no purpose of updating UI after the operation you can simply use Thread to do it.


You can use background handler thread for your purpose.

private Handler mHandler = null;  // global variableprivate HandlerThread mHandlerThread = null; // global variable

// Create instance inside onCreate() or another place inside your code so it would be called one's. Also you can make it singleton if required but it's not the right way.

    mHandlerThread = new HandlerThread("HandlerThread");    mHandlerThread.start();    mHandler = new Handler(mHandlerThread.getLooper());

// perform background operation like :

handler.postDelayed(new Runnable() {                    @Override                    public void run() {                       // Do background work here.                   }                }, 2000);