In the following snippet:
public class ExternalClass {
private int num = 1;
public void backgroundTask() {
new HttpTask().execute();
}
public int getNum() {
return num;
}
private class HttpTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
//Do stuff...
}
@Override
protected void onPostExecute(String result) {
//Do stuff...
ExternalClass.this.num = 2;
}
}
In an Activity:
...
ExternalClass ec = new ExternalClass();
ec.backgroundTask();
int myNum = ec.getNum(); //NUM IS 1, NOT 2!!
What am I doing wrong? Everything works fine, my doInBackground() and onPostExecute() complete successfully but the field "num" don't change. I tried "num = 2" or even "this.num = 2" (I know is no correct, but...).