In short, my class that extends an AsyncTask, downloads a series of data of type byte, then I need to perform some calculations with that data, and finally return all these values to my MainActivity.
The code is summarized as follows:
class DataDownloaderTask extends AsyncTask<String, Void, byte[]> {
private String url;
private Context context;
private static byte[] data;
//--------------------CONSTRUCTOR--------------------------------//
public DataDownloaderTask(Context context) {
this.data = null;
this.context = context;
}
//--------------BACKGROUND---------------------------------------//
@Override
// Actual download method, run in the task thread
protected byte[] doInBackground(String... params) {
// params comes from the execute() call: params[0] is the url.
return downloadData(params[0]);
}
//--------------POST EXECUTE-------------------------------------//
@Override
// Once the image is downloaded
protected void onPostExecute(byte[] data) {
if(data != null){
Toast.makeText(this.context,"Operação concluida com sucesso!", Toast.LENGTH_SHORT).show();
}else{
pDialog.dismiss();
Toast.makeText(this.context,"O ficheiro nao existe ou ocorreu um erro de conexão!", Toast.LENGTH_SHORT).show();
}
}
The method that downloads the data:
static Bitmap downloadData(String url) {
//Download the data from url...
//Calculate other values...
int value1 = 0;
int value2 = 1;
double value 3 = 0.1;
//COMO RETORNAR OS DADOS: value1 value2 value 3 ...?
return data;
}
In my MainActivity I have a method that does this:
DataDownloaderTask object = new DataDownloaderTask(MainActivity.this);
object.execute(string);
try {
mydata = object.get(); //mydata é to tipo byte[]
} catch (Exception e) {
return false;
}
So, I would like to know how I can get other values of different types computed in this same AsyncTask in my MainActivity class, in addition to the "data" byte array. Thanks!