how to pass in two different data types to AsyncTask, Android

前端 未结 3 1875
醉酒成梦
醉酒成梦 2021-01-04 04:34

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 tha

3条回答
  •  一生所求
    2021-01-04 05:01

    You should create a constructor for that.

    public class UpdateInfoAsyncTask extends AsyncTask{
      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();
    

提交回复
热议问题