我有一个扩展AsyncTask
的类。我传入了胆固醇监视器列表,并在onPostExecute
中创建了片段。但是,doInbackground
不能为空方法,onPostExecute
也不能正确覆盖吗?
private class CholesterolFragment extends AsyncTask<ArrayList<CholesterolMonitor>, Void, Void>`{
@Override
protected Void doInBackground(ArrayList<CholesterolMonitor>... arrayLists) {
}
@Override
protected void onPostExecute(ArrayList<CholesterolMonitor> result){
cholesterol_monitor= result;
monitorListFragment = MonitorListFragment.newInstance(cholesterol_monitor);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_monitor_layout, monitorListFragment)
.commit();
}
}
在我的onCreate中,我输入了胆固醇监视器列表:
monitor_list= this.getIntent().getParcelableArrayListExtra("monitorList");
cholesterol_monitor = (ArrayList<CholesterolMonitor>) monitor_list;
CholesterolFragment cholesterolFragment= new CholesterolFragment();
cholesterolFragment.execute(cholesterol_monitor);
答案 0 :(得分:2)
使用空的doInBackground进行异步任务是没有意义的,此时,您没有异步进行任何操作。您也可以直接在主线程上进行操作。
但是答案是doInBackground返回一个值。因此,主体可以返回null;但它需要那种回报。