I am doing some coding stuff with android. Nearly I faced a problem and to solve this I need an anonymous AsyncTask class to execute. But I also need to pass and object to this class before execution. I tried the below code but it's not working and I did not find any solution by googling also.
public void saveCartToRoom(CartsPay cartsPay){
new AsyncTask<Void,Void,Void>(){
CartsPay cartsPay;
@Override
protected Void doInBackground(Void... voids) {
return null;
}
public void setRQ(CartsPay cartsPay){
this.cartsPay= cartsPay;
}
}.setRQ(cartsPay).execute();
}
Here is how to pass a CartsPay
parameter to an anonymousAsyncTask
new AsyncTask<CartsPay,Void,Void>(){
CartsPay cartsPay;
@Override
protected Void doInBackground(CartsPay... params) {
this.cartsPay = params[0];
// Your code ...
return null;
}
public AsyncTask setRQ(CartsPay cartsPay){
this.cartsPay= cartsPay;
return this;
}
}.execute(cartsPay);