lundi 26 mai 2014

How to return data from callback in AsyncTask?


Vote count:

0




I've a really weird problem with AsyncTask class and operation that they're made. My code looks that...



private class BackgroundTask extends AsyncTask < Void, Void, JSONArray >
{
private ProgressDialog pdia;

@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(LoginActivity.this);
pdia.setMessage("...");
pdia.setCanceledOnTouchOutside(false);
pdia.show();
}

@Override
protected Integer doInBackground(Void... params) {

SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://192.168.1.2:3000", new ConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, SocketIOClient client) {
if (ex != null) {
ex.printStackTrace();
return;
}
client.on("MyEvent", new EventCallback() {
@Override
public void onEvent(JSONArray argument, Acknowledge acknowledge) {
////////////
//
// HERE'S MY OUTPUT IN `argument` VARIABLE
//
///////////
}
});
}
});

// return null;
// I need that variable here.
}

protected void onPostExecute(JSONArray result){
super.onPostExecute(result);
Log.d("Result...", result.toString());
pdia.dismiss();
}
}


Data what I need are in onConnectCompleted, but I need it in doInBackground. I can't make global variable for output, because post will be executed to short. So my question is, how can I return my data?



asked 1 min ago

Siper

121





Aucun commentaire:

Enregistrer un commentaire