nic*_*sso 8 java android multi-window android-activity rx-java
我遇到了RxJava,Retrofit和Multi-Window模式的问题......我在Activity中调用了我们自己的api和Retrofit(实际的代码比这复杂一点):
api.getEvent(...)
.subscribeOn(Schedulers.io())
.observeOn(AndroidScheduler.mainThread())
.subscribe(event -> setupUI(event),
throwable -> showSnackbar(throwable));
Run Code Online (Sandbox Code Playgroud)
当应用程序处于"正常"模式(全屏)时,一切运行正常...我可以将应用程序放入bg,将其放回前台并再次调用api调用方法(它位于onResume方法中 - kind并且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)
Run Code Online (Sandbox Code Playgroud)
应用程序不会崩溃但UI仍处于"占位符"状态,加载ProgressBar将永远消失.
编辑:我在其他活动中有相同的代码结构.但问题并没有出现在其他地方.
当应用程序进入多窗口模式时,会发生一些奇怪的生命周期回调序列。我已经记录了onStart、onResume、onPause和onStop。查看结果:
pause
stop
start
resume
pause
Run Code Online (Sandbox Code Playgroud)
因此,首先打开的应用程序会失去焦点,然后获得焦点,然后再次失去焦点(焦点转到下一个窗口)。
我相信您正在取消订阅onPause,因为您在 中发起了订阅onResume。这就是为什么subscribe()永远不会被调用,因为它会立即被取消订阅。
| 归档时间: |
|
| 查看次数: |
185 次 |
| 最近记录: |