虽然覆盖诸如onPostExecute
from之类的方法时,AsyncTask
我们可以避免或删除super.onPostExecute(result);
它。您能告诉我为什么以及何时需要使用此通话吗?因为我在Main Activity中将AsyncTask实现为内部类
private class CustomAsyncTask extends AsyncTask<String, Void, Event> {
@Override
protected Event doInBackground(String... strings) {
Event result = Utils.fetchEarthquakeData(strings[0]);
return result;
}
@Override
protected void onPostExecute(Event result) {
super.onPostExecute(result);// what is the effect of calling this? If it was possible to skip or remove it.
updateUi(result);
}
}
覆盖方法时,将重新定义该方法,即,如果在子类的实例(已覆盖该方法的实例)上调用了此方法,则将调用此新版本的定义。
当您覆盖方法时(即,重新定义或换句话说,将超类定义替换为该定义的子版本),您有两种选择:
请注意,正如安迪·特纳(Andy Turner)所指出的那样,调用super的要求被视为反模式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句