Domanda

Ciao ogni volta che installo app, aprila piuttosto che chiuderla con il pulsante Indietro e di nuovo riaprivo ottengo lo stesso errore:

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)]

Ho letto che devo fare funzione di onrestart (COLLEGAMENTO) ... ma non ho idea di come gestirlo ...

funzione oncreate fai le seguenti cose:

  1. Imposta layout
  2. Imposta tutti gli oggetti necessari (ProgressDialog, ArrayList, ChanneliteMadapter, ChannelDBadapter)
  3. Carica i dati in asyncTask: new LoadChannels().execute(channelItem);

Come ho detto prima, funziona perfettamente e quando navighi nell'app ... ma quando si lascia l'app e riavviala, si schiaccia sempre ...

Grazie per l'aiuto!


Codice aggiunto:

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
}
È stato utile?

Soluzione

Dalla traccia dello stack che hai fornito, sembra che tu modifichi il contenuto dell'adattatore ListView al di fuori del thread dell'interfaccia utente. Penso che dovresti dare un'occhiata al tuo asyncTask per essere sicuro di eseguire modifiche sul tuo adattatore solo sui metodi eseguiti nel thread dell'interfaccia utente (non in DoinBackground per esempio).

Vedere Asynctask

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top