I have an application in the market with a bug which I can not seem to solve. Today I have tracked it down to the following method.
public void updateDealList(ArrayList<Deal> deals) {
// first call or showing bookmakrs (also gets called other times when adapter is null)
if (dealListAdapter == null || showingBookmarks || !dealListAdapter.moreDealsToDownload()) {
dealListAdapter = new EndlessDealListAdapter(getActivity(),
R.layout.deal_list_item, deals);
setListAdapter(dealListAdapter);
listView = getListView();
if (getActivity().findViewById(R.id.right_fragment_container)!=null){ // if tablet
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
}
showingBookmarks=false;
Log.d("UPDATE_DEAL_LIST", "Notified list created new" + dealListAdapter.getCount());
return; //PROBLEM OCCURS WHEN APP COMES IN HERE AFTER RESUMING
}
dealListAdapter.getDealListAdapter().clear();
for (Deal d: deals){
dealListAdapter.getDealListAdapter().add(d);
Log.d("UPDATE_DEAL_LIST", "added " + d.title);
}
dealListAdapter.notifyDataSetChanged();
Log.d("UPDATE_DEAL_LIST", "Notified list " + dealListAdapter.getCount());
}
This method is passed an arraylist of deal objects which are pulled down from the internet. When the application is first opened data is pulled from the internet and the above method is called which creates a new adapter which is set for the ListFragment. This method is also called when the user requests more deals.
The problem I am having is that the list sometimes thinks its empty dispite the adapter containing deals. This seems to occur when a use resume the application when their device is low on memory (I presume part of the application has been removed from ram). This method is called and the dealListAdapter is null so a new one is created and deals are added. Despite this happening the list remains empty and the user has to force close the app to get it working again.
The line below shows tat when the method is called it enters the if and 21 deals are added to the adapter. Unfortunately the list is empty to the user.
05-23 01:52:32.879: D/UPDATE_DEAL_LIST(3478): Notified list created new21