【发布时间】:2015-04-05 18:12:04
【问题描述】:
我正在尝试 Toast 完成一个服务电话。但是在 onComplete 方法中我收到了这个异常:
java.lang.RuntimeException: 无法在未调用 Looper.prepare() 的线程内创建处理程序
它是从SafeSubscriber#onNext(T args) 抛出的,看起来像这样:
/**
* Provides the Subscriber with a new item to observe.
* <p>
* The {@code Observable} may call this method 0 or more times.
* <p>
* The {@code Observable} will not call this method again after it calls either {@link #onCompleted} or
* {@link #onError}.
*
* @param args
* the item emitted by the Observable
*/
@Override
public void onNext(T args) {
try {
if (!done) {
actual.onNext(args);
}
} catch (Throwable e) {
// we handle here instead of another method so we don't add stacks to the frame
// which can prevent it from being able to handle StackOverflow
Exceptions.throwIfFatal(e);
// handle errors if the onNext implementation fails, not just if the Observable fails
onError(e);
}
}
这是我的代码中出现问题的代码 sn-p:
NetworkService.aService()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatmap(anotherCall)
.subscribe(new Subscriber<AddCommentResponse>() {
@Override
public void onCompleted() {
Toast.makeText(...).show();
navigateBack();
}
// etc. ...
是我无法从 onCompleted 方法更新 UI 的问题吗?或者我应该在哪里处理 UI 操作?
【问题讨论】:
标签: java android observable rx-java