Android Onrestartアプリの問題
-
29-10-2019 - |
質問
こんにちは、アプリをインストールするたびに、バックボタンで閉じるよりも開き、再び再開するよりも、同じエラーが発生します。
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)]
Onrestart関数を作らなければならないことを読みました(リンク)...しかし、私はそれを処理する方法がわかりません...
OnCreate関数は次のことを行います。
- レイアウトを設定します
- 必要なオブジェクトをすべて設定します(ProgressDialog、ArrayList、ChannelItemadapter、ChannelDBadapter)
- Asynctaskにデータをロードします:
new LoadChannels().execute(channelItem);
私が前に言ったように、それが完全にスタートし、アプリを閲覧するとき...しかし、アプリを離れて再起動するとき、それは常に押しつぶされます...
ご協力いただきありがとうございます!
追加コード:
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
}
解決
提供したスタックトレースから、UIスレッドの外側のListViewアダプターのコンテンツを変更するようです。 Asynctaskを確認して、UIスレッドで実行されているメソッド(Doinbackgroundではなく)でのみアダプターで変更を実行するようにする必要があると思います。
見る asynctask
所属していません StackOverflow