i have a method that does an SQLite database update and put this inside of an AsyncTask to make it faster and more reliable.
however there are two pieces of data that are needed to update the database. one is an Integer and the other is an object of the PrimaryKeySmallTank class that is shown here.
using the params array in the arguments of the doInBackground method of AsyncTask, i can pass an Integer in, but what if I have two different types of data like here?
if an integer is stored in int... params[0] i cannot store a different type object in params[1], so what can be done about this?
object i want to pass into the AsyncTask
public class PrimaryKeySmallTank {
int contractNumber;
int customerCode;
int septicCode;
String workDate;
int workNumber;
}
the AsyncTask that i am using
public class UpdateInfoAsyncTask extends AsyncTask<Integer, Void, Void>{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
protected Void doInBackground(Integer... params) {
Integer mIntegerIn = params[0]; // this is what I want to do, example
PrimaryKeySmallTank mPrimaryKeySmallTank = params[1]; // different data type to pass in
Database db = new Database(InspectionInfoSelectionList.this);
db.openToWrite();
db.updateWorkClassificationByRow(mPrimaryKeySmallTank, mIntegerIn);
db.close();
return null;
}
} // end UpdateInfoAsyncTask
You should create a constructor for that.
public class UpdateInfoAsyncTask extends AsyncTask<Void, Void, Void>{
int intValue;
String strValue;
public UpdateInfoAsyncTask(int intValue,String strValue){
this.intValue = intValue;
this.strValue = strValue;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
protected Void doInBackground(Void... params) {
//use intValue
//use strValue
return null;
}
}
To use it
new UpdateInfoAsyncTask(10,"hi").execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With