Android onRestart应用程序问题
嗨,每次我安装应用程序时,用“上一步”按钮打开然后关闭,然后再次重新打开,我都会收到相同的错误:Android onRestart应用程序问题,android,onresume,application-restart,Android,Onresume,Application Restart,嗨,每次我安装应用程序时,用“上一步”按钮打开然后关闭,然后再次重新打开,我都会收到相同的错误: 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 adapte
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函数执行以下操作:
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
}
受保护的ArrayList doInBackground(ArrayList…正在传递)
{
cItems=传递[0];//获取传递的arraylist
toDoListCursor=channelDBAdapter.getAllToDoItemsCursors();
startManagingCursor(toDoListCursor);
channelItem.clear();
if(toDoListCursor.moveToFirst())
做
{
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_chu COU_ID));
ToDoItem newItem=新ToDoItem(任务、已创建、fav、id、CHU类型、国家/地区);
channelItem.add(0,newItem);
}
while(toDoListCursor.moveToNext());
return cItems;//返回结果
}
根据您提供的堆栈跟踪,您似乎在UI线程之外修改了ListView适配器的内容。我认为您应该查看一下ASyncTask,以确保仅对在UI线程中执行的方法(例如,不在doInBackground中)执行适配器上的修改
请参见我在问题中添加了上面asyncTask中的代码。。。我做修改。。。但这就是asyncTask的要点……asyncTask的目的是执行会减慢主线程速度的繁重任务。因此,
doInBackground
方法在一个单独的线程上执行,但是适配器不能从与UI线程不同的线程更新。在doInBackground方法中准备您的修改,但是在onPostExecute
方法中修改头,您将避免抛出此异常。太棒了!很好的帮助我现在明白了,并且很高兴地修复了一切!谢谢