Android, ListView IllegalStateException: "The content of the adapter has changed but ListView did not receive a notification"


What I want to do: run a background thread which calculates ListView contents and update ListView partially, while results are calculated.

What I know I have to avoid: I cannot mess with ListAdapter contents from background thread, so I inherited AsyncTask and publish result (add entries to adapter) from onProgressUpdate. My Adapter uses ArrayList of result objects, all operations on those arraylists are synchronized.

Research of other people: there is very valuable data here. I also suffered from almost daily crashes for group of ~500 users, and when I added list.setVisibility(GONE)/trackList.setVisibility(VISIBLE) block in onProgressUpdate, crashes lowered by a factor of 10 but not disappeared. (it was suggested in answer )

What I got sometimes: please notice, it happens really rarely (once a week for one of 3.5k users). But I'd like to get rid of this bug completely. Here is partial stacktrace:

`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(
at android.widget.AbsListView.onTouchEvent(
at android.widget.ListView.onTouchEvent(
at android.view.View.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(
at android.view.ViewGroup.dispatchTouchEvent(

Help? Not needed anymore, see below

FINAL ANSWER: As it turned out, I was calling notifyDataSetChanged every 5 insertions to avoid flickering and sudden list changes. It cannot be done such way, always notify adapter when base list changes. This bug it long gone for me now.

2/6/2015 6:31:01 AM

Accepted Answer

I had the same issue.

I was adding items to my ArrayList outside the UI thread.

Solution: I have done both, adding the items and called notifyDataSetChanged() in the UI thread.

2/21/2017 3:02:20 PM

I had the same problem, but I fixed it using the method


from the class ListView

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow