Open ychdevelop opened 6 years ago
在子线程前面加上:
Looper.prepare();
完整代码:
private void loadData() {
Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Directory<NormalFile>>>() {
@Override
public void subscribe(ObservableEmitter<List<Directory<NormalFile>>> emitter) throws
Exception {
Looper.prepare();
FileFilter.getFiles(NormalFilePickActivity.this, new FilterResultCallback<NormalFile>() {
@Override
public void onResult(List<Directory<NormalFile>> directories) {
// Refresh folder list
emitter.onNext(directories);
emitter.onComplete();
}
}, mSuffix);
}
}).subscribeOn(Schedulers.io())//异步任务在IO线程执行
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<Directory<NormalFile>>>() {
@Override
public void accept(List<Directory<NormalFile>> directories) throws Exception {
if (isNeedFolderList) {
ArrayList<Directory> list = new ArrayList<>();
Directory all = new Directory();
all.setName(getResources().getString(R.string.vw_all));
list.add(all);
list.addAll(directories);
mFolderHelper.fillData(list);
}
mAll = directories;
refreshData(directories);
}
});
}
在子线程前面加上:
Looper.prepare();
完整代码:
private void loadData() { Disposable disposable = Observable.create(new ObservableOnSubscribe<List<Directory<NormalFile>>>() { @Override public void subscribe(ObservableEmitter<List<Directory<NormalFile>>> emitter) throws Exception { Looper.prepare(); FileFilter.getFiles(NormalFilePickActivity.this, new FilterResultCallback<NormalFile>() { @Override public void onResult(List<Directory<NormalFile>> directories) { // Refresh folder list emitter.onNext(directories); emitter.onComplete(); } }, mSuffix); } }).subscribeOn(Schedulers.io())//异步任务在IO线程执行 .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<List<Directory<NormalFile>>>() { @Override public void accept(List<Directory<NormalFile>> directories) throws Exception { if (isNeedFolderList) { ArrayList<Directory> list = new ArrayList<>(); Directory all = new Directory(); all.setName(getResources().getString(R.string.vw_all)); list.add(all); list.addAll(directories); mFolderHelper.fillData(list); } mAll = directories; refreshData(directories); } }); }
报错了
rt