Here’s a part of a code that should do something and then call the onPostExecute event.
For some reason, it doesn’t call it, and in eclipse I can see that the method is marked with yellow (not used method)…
I cant understand why its this way…
Do you know why?
Thank you!
PS: I looked into some posts here and didn’t find my solution…
final ImageButton sync = (ImageButton) findViewById(R.id.syncChanges);
sync.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sync.setImageResource(R.drawable.none);
sync.setBackgroundResource(R.drawable.animation);
final AnimationDrawable frameAnimation = (AnimationDrawable) sync.getBackground();
frameAnimation.start();
class DownloadFilesTask extends AsyncTask<String, Void, String[]> {
protected String[] doInBackground(String...strings) {
try {
OptionScraper.run(strings[0], Integer.parseInt(strings[1]));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return OptionScraper.GetChanges();
}
protected void onPostExecute() {
InitChangesToText();
frameAnimation.stop();
sync.setImageResource(R.drawable.sync);
}
}
new DownloadFilesTask().execute(classLetter,classNum);
}
});
You are not overriding
onPostExecute()correctly. It takes one argument (the object you return fromdoInBackground()). But you override/create the method with a signature that takes no arguments. Which means that the framework calls the default implementation instead of your own. Which does nothing at all.So change
to
in this case.
I also recommend adding an
@Overrideannotation to that method, in this case eclipse or a similar tool should have pointed that out in the first place.