This was discussed earlier here Android, ListView IllegalStateException: "The content of the adapter has changed but ListView did not receive a notification" but I still have the problem. I've got Service, which dowloads data from web, saves it do db and fires intent when it's completed. My Activity has ListView and BroadCast receiver:
private class NewsUpdateReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
mNotificationManager.cancel(NewsService.NOTIFICATION_ID);
loadNewsFromDB();
}
}
private void loadNewsFromDB(){
mList.clear();
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(MeidahonProvider.CONTENT_URI, null, null, null, null);
if(cursor.moveToFirst()){
do{
String title = cursor.getString(MeidahonProvider.TITLE_COLUMN);
String description = cursor.getString(MeidahonProvider.DESCRIPTION_COLUMN);
String link = cursor.getString(MeidahonProvider.LINK_COLUMN);
long datems = cursor.getLong(MeidahonProvider.DATE_COLUMN);
Date date=new Date(datems);
NewsItem item = new NewsItem(title, description, link, date);
mList.add(item);
mAdapter.notifyDataSetChanged();
}while(cursor.moveToNext());
}
cursor.close();
}
Every time when item is add to ArrayList, I call mAdapter.notifyDataSetChanged();
but still have exception. How can I solve the problem?
UPD LOG
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131296334, class android.widget.ListView) with Adapter(class com.transportoid.Tracks.TrackListAdapter)]
at android.widget.ListView.layoutChildren(ListView.java:1432)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:2062)
at android.widget.ListView.onTouchEvent(ListView.java:3234)
at android.view.View.dispatchTouchEvent(View.java:3709)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)