SQL query with Asynctask passing parameter

1

I'm doing a class that extends Asynctask to make a modification to my database SQLite Android, to perform the query you must pass a parameter to the method of the query, but I do not know how to pass it to the Asynctask class, I have this for now:

 public class AsyncTaskDB extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... voids) {
    updateShowMain0(/*Parametro articulo*/);
    return null;
}

public void updateShowMain0(String articulo){
    SQLiteDatabase db = Utility.dbHelper.getReadableDatabase();
    /*ContentValues valores = new ContentValues();
    valores.put("showMain", 0);
    Log.i("","Recibe la consulta");
    return db.update("articles",valores,"description = ?", new String[]{articulo});
*/
    db.execSQL("UPDATE articles SET showMain = 0 WHERE description = ?", new String[]{articulo});
    Log.i("","Recibe la consulta");

}


}

I would like the doinbackground to run when changing the status of a checkbox, could someone guide me a little?

Greetings.

    
asked by J. Burrueco 03.01.2019 в 10:51
source

1 answer

2

Your AsyncTaskDB class inherits from AsyncTask. As you will notice there are 3 parameters that you have as Void. That parameter is the one that you have to change if you decide to pass some data when executing the asynchronic tasks.

For example, if you want to pass an integer, you would need something like this:

public class AsyncTaskDB extends AsyncTask<Integer, Void, Void> {

@Override
protected Void doInBackground(Integer... params) {
    //Recuerda que params es un arreglo
    updateShowMain0(params[0]);
    return null;
}
    
answered by 03.01.2019 / 12:40
source