美文网首页Android知识
Volley使用时com.android.volley.NoCo

Volley使用时com.android.volley.NoCo

作者: 快乐猿Days | 来源:发表于2017-11-10 14:30 被阅读315次

      维护一个老项目时,发现经常第一请求某个接口时会弹一个“没有网络” Toast。明明是有网的呀,为啥只是偶尔出现。带着疑问一路追踪下去

原来Volley 报出了个“com.android.volley.NoConnection error, java.io.InterruptedIOException”,为什么回报这个错误呢?我们来看一下源码:

发现RequestQueue初始化时已经 start()了,而我工程里调用接口时又 start()了一次,那么是不是它的原因呢?我们进入 start()方法里看一下:

 这里我们直接看到,先走 stop() 方法,我们继续跟进看看它做了什么:

Interrupt this thread before running actions so that other threads that observe the interrupt as a result of an action will see that this thread is in the interrupted state.

到此我恍然大悟,原来如此!

相关文章

网友评论

    本文标题:Volley使用时com.android.volley.NoCo

    本文链接:https://www.haomeiwen.com/subject/jtebmxtx.html