When the Activity is destroyed, the network request needs to be canceled. For example, Volley usually calls VolleyRequest.cancelPendingRequests(tagName);
If you don’t know anything else, just Volley而言是不会取消网络请求的, 即使你使用了cancel方法, 也不会停止网络请求, 使用了cancel方法只是不进行回调, 实际上网络请求是后台线程, 还有超时限制, 所以网络请求即使不停止影响也不是很大. 关键是不能再生命周期结束后回调方法, 所以在Activity you have to cancel the request when it ends
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.
When the Activity is destroyed, the network request needs to be canceled. For example, Volley usually calls VolleyRequest.cancelPendingRequests(tagName);
in onStop()If you don’t know anything else, just
Volley
而言是不会取消网络请求的, 即使你使用了cancel方法, 也不会停止网络请求, 使用了cancel方法只是不进行回调, 实际上网络请求是后台线程, 还有超时限制, 所以网络请求即使不停止影响也不是很大. 关键是不能再生命周期结束后回调方法, 所以在Activity
you have to cancel the request when it endsNetwork 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.
Under normal circumstances, Retrofit tasks will continue after the Activity is destroyed. We can only choose whether to receive callbacks
Obviously, you need to cancel it yourself