发现问题
在项目开发中发现,发起网络请求是会一直显示Loading。但是我们在okhttp初始化的时候已经设置的网络请求超时时间为30s。为什么会出现这种情况 WTF!
解决问题
通过断点调试发现,在AsyTask中发起网络请求的位置停住了。导致线程一直无法中断。通过一步一步断点发现。
Code
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
this.streamAllocation = new StreamAllocation(this.client.connectionPool(), this.createAddress(request.url()));
int followUpCount = 0;
Response priorResponse = null;
//while循环
while(!this.canceled) {
Response response = null;
boolean releaseConnection = true;
try {
response = ((RealInterceptorChain)chain).proceed(request, this.streamAllocation, (HttpStream)null, (Connection)null);
releaseConnection = false;</