Issue
I have a class that extends AsyncTask
. I pass in a list of cholesterol monitors and create the fragment in onPostExecute
. However, doInbackground
cannot be an empty method and onPostExecute
also doesn't override correctly?
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();
}
}
In my onCreate I pass in the cholesterol monitor list:
monitor_list= this.getIntent().getParcelableArrayListExtra("monitorList");
cholesterol_monitor = (ArrayList<CholesterolMonitor>) monitor_list;
CholesterolFragment cholesterolFragment= new CholesterolFragment();
cholesterolFragment.execute(cholesterol_monitor);
Solution
There's no point in having an async task with an empty doInBackground, at that point you aren't doing anything asynchronously. You may as well just do it directly on the main thread.
But the answer is that doInBackground returns a value. So the body can just be return null; but it needs that return.
Answered By - Gabe Sechan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.