So im using the endlessadapter from commonsware on a fragment and the issue i have is that every time i rotate while the adapter is waiting to finish loading some data, the cacheInBackground method is called again. The initialization of the adapter is called on the onActivityCreated method from the fragment, so how i can i simply resume the result of the first call of cacheInBackground method?
IpdmsEndlessAdapter endAdapt= new IpdmsEndlessAdapter(getActivity(),adapter,R.layout.list_loading_row){
@Override
protected boolean cacheInBackground() throws RequestException{
tempList.clear();
List<MyProcessDTO> myPRocs;
myPRocs = new MyprocessesManager(getActivity()).getMyProcessesFromServer(processListPage);
if(myPRocs!=null){
tempList.addAll(myPRocs);
}else
return false;
//return true if there's more data do return
//return false if there was an error or there's no more data
return myPRocs.size()>=10;
}
@Override
protected boolean onException(View pendingView, Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
}
@Override
protected void appendCachedData() {
@SuppressWarnings("unchecked")
GenericMenuAdapter a=(GenericMenuAdapter)getWrappedAdapter();
for(MyProcessDTO myProcessDTO:tempList){
a.add(new IpdmsMobileMenuItemListDTO(myProcessDTO.getNrprocesso(), myProcessDTO.getEtapa(), 0, myProcessDTO));
}
processListPage++;
}
};
actualListView.setAdapter(endAdapt);
regards,
Make this be a dynamic fragment (i.e., set it up via a
FragmentTransaction) and callsetRetainInstance(true)on it somewhere during setup (e.g.,onActivityCreated()). This will keep the adapter instance between configuration changes.There may still be some issues with a configuration change while the background thread is doing its work. If you are running into problems even after applying the above recommendations, post a comment on this answer.