안녕하세요 현재 안드로이드개발자를 꿈꾸는 꿈나무 학생입니다. 고수님들께 질문이 있어
이렇게 질문남깁니다...ㅠ
현재 폴더에 대한 목록을 가져와 리스트뷰에 뿌리는 activity를 구현하고있습니다.
usb에 파일이 1만개가있을시에 파일리스트를 가져오면서 ANR이 발생하여
아래와같이 Asynctask를 사용하여 백그라운드에서 화면이 보여지도록 수정하였습니다.
FATAL EXCEPTION: main
E/AndroidRuntime( 1840): Process: com.ds.music, PID: 1840
E/AndroidRuntime( 1840): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131230759, class android.widget.ListView) with Adapter(class com.ds.music.DSMusicListActivity$MusicListAdapter)]
그런데 잘되다가 어쩔대 한번씩 위와같은 로그가 찍히면서 죽습니다.
아래코드를 보시면 mainThread에서 어댑터의 데이터를 체인지해주는데 저런 로그가 왜뜨는 것인지
모르겠고, 수정을 어떻게해야하는지도 잘모르겠습니다....ㅠ 고수님들 제발...ㅠ도와주세요....ㅠ
private class ListUpChange extends AsyncTask<Void, Void, Void>{
@Override
protected void onPreExecute() {
super.onPreExecute();
fileListSet.setVisibility(View.VISIBLE);
mAllFile.clear();
DSMusicListActivity.this.runOnUiThread(dataRefresh);
folderNum=0;
Log.e("jilee","excute start");
}
@Override
protected Void doInBackground(Void ... params) {
File fileDir = new File(defaultPath);
File[] filesDir = folderFilterling(fileDir);
if(mListUpChange.isCancelled())return null;
if (filesDir.length > 0){
filesDir = mService.sortFileList(filesDir);
for(File file : filesDir){
if(file.isDirectory()){
if(mListUpChange.isCancelled())return null;
mAllFile.add(file);
}
}
folderNum = mAllFile.size();
}
File[] files = fileFilterling(fileDir);
if(mListUpChange.isCancelled())return null;
if (files.length > 0){
files = mService.sortFileList(files);
for (int i = 0; i < files.length; i++) {
if(!mListUpChange.isCancelled()){
mAllFile.add(files[i]);
}else{
return null;
}
}
}
for(int i = 0; i < mAllFile.size(); i++){
if(!mListUpChange.isCancelled()){
if(fullPath.equalsIgnoreCase(mAllFile.get(i).getAbsolutePath())){
if(defaultPath.equalsIgnoreCase(mRoot)){
myChoiceListNum = i;
}else{
myChoiceListNum = i+1;
}
}
}else{
return null;
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mHandler.postDelayed(focusSet, 1000);
listUpStop=true;
}
@Override
protected void onCancelled() {
super.onCancelled();
listUpStop=true;
}
}
private Runnable focusSet = new Runnable() {
@Override
public void run() {
DSMusicListActivity.this.runOnUiThread(dataRefresh);
}
};
private Runnable dataRefresh = new Runnable() {
@Override
public void run() {
mAdapter.dataChange();
}
};