Reputation: 1971
i'm tryng to change some UI elements from an n AsyncTask' onPostExecute() method but it doesn't work...i don't know why I've done it a few times earlier and it worked without any problem....the task uploads a photo to a server, it works; i don't care of results for now just want to write something on the UI
mainactivity code:
ImageUpload post=new ImageUpload(imagePath.toString(),textView);
//post.delegate=this;
post.execute(imagePath.toString());
asyncTask code:
public class ImageUpload extends AsyncTask<String, Void, Void>{
public TextView resp;
public ImageUpload(String photoPath, TextView resp){
//other stuff
this.resp=resp;
}
@Override
protected Void doInBackground(String... params) {
//upload photo
}
protected void onPostExecute(Void... params) {
resp.setText("work done");
}
}
the file is uploaded but the textview doesn't change.... anyone can see the error?
Upvotes: 0
Views: 694
Reputation: 9700
Here, you miss 2 things...
1. to return null
in doInBackground
method
2. to add @Override
notation before onPostExecute
method
@Override
protected Void doInBackground(String... params) {
//upload photo
return null; //you have to return a null for Void
}
@Override
protected void onPostExecute(Void result) {
resp.setText("work done");
}
Upvotes: 0
Reputation: 48612
You have to write the onPostExecute
like this
@Override
protected void onPostExecute(Void params) {
resp.setText("work done");
}
Upvotes: 4