سؤال

Hi everytime I install app, open it than close it with back button and than again reopen it I get the same error:

05-05 10:49:35.453: ERROR/AndroidRuntime(5118): 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(2131361820, class android.widget.ListView) with Adapter(class com.TVSpored.ChannelItemAdapter)]

I have read that I have to make onRestart function (LINK)... but I have no idea how to handle it...

onCreate function do the following things:

  1. set layout
  2. set all necessary objects (ProgressDialog, ArrayList, ChannelItemAdapter, channelDBAdapter)
  3. Loads data in asynctask: new LoadChannels().execute(channelItem);

As I have said before it work perfectly onStart and when browsing the app... but when leaving the app and restart it, it always crushes...

Thanks for your help!


Added code:

protected ArrayList<ToDoItem> doInBackground(ArrayList<ToDoItem>... passing) 
{

    cItems = passing[0]; //get passed arraylist
    toDoListCursor = channelDBAdapter. getAllToDoItemsCursor();
    startManagingCursor(toDoListCursor);
    channelItem.clear();
    if (toDoListCursor.moveToFirst())
    do 
    { 
      String task = toDoListCursor.getString(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_NAME));
      String created = toDoListCursor.getString(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_EPG_NAME));
      int fav = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_FAV));
      int id = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_EPG_ID));
      int ch_type = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_CH_CHTYPE_ID));
      int country = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_CH_COU_ID));
      ToDoItem newItem = new ToDoItem(task, created, fav, id, ch_type, country);
      channelItem.add(0, newItem);
    } 
    while(toDoListCursor.moveToNext());


    return cItems; //return result
}
هل كانت مفيدة؟

المحلول

From the stack trace you have provided, it seems you modify the content of your ListView Adapter outside of the UI thread. I think you should have a look at your ASyncTask to be sure that you perform modifications on your adapter only on methods that are executed in the UI thread (not in doInBackground for example).

See ASyncTask

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top