比如,AsynaTask生命周期就需要考虑,与Activity生命周期不一致。
大家讲道理2017-04-17 17:50:38
When the Activity is destroyed, the network request needs to be canceled. For example, Volley usually calls VolleyRequest.cancelPendingRequests(tagName);
in onStop()巴扎黑2017-04-17 17:50:38
If you don’t know anything else, just Volley
而言是不会取消网络请求的, 即使你使用了cancel方法, 也不会停止网络请求, 使用了cancel方法只是不进行回调, 实际上网络请求是后台线程, 还有超时限制, 所以网络请求即使不停止影响也不是很大. 关键是不能再生命周期结束后回调方法, 所以在Activity
you have to cancel the request when it ends
怪我咯2017-04-17 17:50:38
Network requests are newly opened threads. Generally, the destruction of the main thread has little impact. The key is the callback of the network thread. We usually do something in the main thread, but at this time the main thread has been destroyed. So we still have to handle cancel manually.
巴扎黑2017-04-17 17:50:38
Under normal circumstances, Retrofit tasks will continue after the Activity is destroyed. We can only choose whether to receive callbacks