4
Briefly, my class that extends an Asynctask, downloads a series of data byte type, then I need to perform some calculations with this data, and finally return all these values to my Mainactivity.
The code boils down to:
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;
}
Therefore, I would like to know how I can obtain in my Mainactivity class, in addition to the "data" byte array, other values of different types calculated in that same Asynctask. Thank you!
Thank you very much :D
– MarcoAF