我遇到了RxJava,Retrofit和Multi-Window模式的问题...... 我在Activity中使用Retrofit调用我们自己的api(实际代码比这更复杂):
api.getEvent(...)
.subscribeOn(Schedulers.io())
.observeOn(AndroidScheduler.mainThread())
.subscribe(event -> setupUI(event),
throwable -> showSnackbar(throwable));
当应用程序处于“正常”模式(全屏)时,一切运行正常......我可以将应用程序放入bg,将其放回前台并再次调用api调用方法(它位于onResume中)方法 - 种类)和UI绘制没有问题。 当我激活多窗口模式时,调用onResume,成功调用api方法,但永远不会到达subscribe()方法。 这种情况的堆栈跟踪是:
Retrofit: java.io.InterruptedIOException: thread interrupted
at okio.Timeout.throwIfReached(Timeout.java:145)
at okio.Okio$1.write(Okio.java:77)
at okio.RealBufferedSink.flush(RealBufferedSink.java:221)
at com.squareup.okhttp.internal.framed.Http2$Writer.flush(Http2.java:381)
at com.squareup.okhttp.internal.framed.FramedConnection.newStream(FramedConnection.java:283)
at com.squareup.okhttp.internal.framed.FramedConnection.newStream(FramedConnection.java:249)
at com.squareup.okhttp.internal.http.Http2xStream.writeRequestHeaders(Http2xStream.java:135)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:710)
at com.facebook.stetho.okhttp.StethoInterceptor.intercept(StethoInterceptor.java:67)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
at com.squareup.okhttp.Call.getResponse(Call.java:287)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205) at com.squareup.okhttp.Call.execute(Call.java:80)
at com.newrelic.agent.android.instrumentation.okhttp2.CallExtension.execute(CallExtension.java:43)
at retrofit.client.OkClient.execute(OkClient.java:53)
at com.newrelic.agent.android.instrumentation.retrofit.ClientExtension.execute(ClientExtension.java:42)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)
at retrofit.RxSupport$2.run(RxSupport.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:761)
应用程序不会崩溃,但UI仍处于“占位符”状态,加载ProgressBar将永远消失。
编辑:我在其他活动中拥有相同的代码结构。但问题并没有出现在其他地方。