I've 6 different type of List results after completing AsyncTask. And the List results are should be returned to an Activity. For example: List<A>, List<B>, List<C>, List<D>, List<E> and finally List<F>.
This is my AsyncTask:
public class myAsync extends AsyncTask<String, String, List> {
private List resultList;
@Override
protected List doInBackground(String... params) {
//params[0] is url
//params[1] is type
callAPI api = new callAPI(params[0], params[1]);
// According to type api decides type of List and generates
return api.getJSON(); // returns a List which already parse JSON
}
@Override
protected void onPostExecute(List result) {
// Result is here now, may be 6 different List type.
this.resultList = result
}
// returns result
public List getResultList() { return this.resultList; }
}
I'll call AsyncTask like this:
myAsync task = new myAsync();
task.execute(params);
List myList = task.getResultList(); // type is uncertain
Log.d("Tag", Integer.toString(myList.size());
You know, I must point out the return type (Result) between <> tags. If I choose specific type for List, it does not work for other types.
Indeed, I already tried to return List<Object> and only List types. But doesn't worked.
I don't want to use 6 different Async. Is it possible to solve this with an only AsyncTask? I guess I need anonymous List or something similiar not sure. Can anyone explain this?
AsyncTask<String, String, List>. If it is, what's going to be return types? I already returned all types as a normal List, got an NullException error.