9

当应用程序处于后台时,我需要发出网络调用。顺序如下。应用程序接收 GCM 调用,向 BE 发出 API 调用以获取更多数据,然后显示通知。GCM 调用被完美接收,但 API 网络调用因超时而失败,原因如下stack-trace

java.net.SocketTimeoutException: timeout
                                                    at okio.Okio$3.newTimeoutException(Okio.java:207)
                                                    at okio.AsyncTimeout.exit(AsyncTimeout.java:250)
                                                    at okio.AsyncTimeout$2.read(AsyncTimeout.java:217)
                                                    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
                                                    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
                                                    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
                                                    at com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
                                                    at com.squareup.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
                                                    at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
                                                    at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
                                                    at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
                                                    at com.nuro.newcoms.NuroCommunicationService$21.intercept(NuroCommunicationService.java:1986)
                                                    at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
                                                    at com.nuro.encryption.NuroSSLContext$1.intercept(NuroSSLContext.java:94)
                                                    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 retrofit.client.OkClient.execute(OkClient.java:53)
                                                    at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
                                                    at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
                                                    at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
                                                    at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                    at java.lang.Thread.run(Thread.java:761)`

我正在使用okhttpver 2.7.5retrofit 1.9.0

该应用程序在后台,但设备没有打瞌睡,屏幕打开,甚至正在充电。所以这不可能是打瞌睡的问题。

发生在WiFi和上3/4G

pre-nougat设备没有这个问题。

UPD 当应用程序在电池设置中被选择为“未优化”时,一切都像一个魅力。

4

0 回答 0