PaperPlane
PaperPlane copied to clipboard
Cancel the network request in ondestroy() of the activity, should you consider it
Hi, @Vector-SMG
I cannot understand what do you mean, because I do not make any network request in Activity. All the network requests are sending in Fragment. But like you point out, cancelling the request when the activity or fragment is going to destroy is necessary. If you find anything wrong about that, show me more details so I can fix it.
@TonnyL 在Activity或者fragment的onDestroy()的生命周期中,有可能当前界面中,还存在网络请求在执行,导致内存溢出或者空指针异常等等。所以取消网络请求是必要的,当前主流做法:1.如果网络请求中,用到rxjava,使用RxLifecycle来全局取消 2.使用ViewModel+LiveData来管理。是否考虑将其加入?完善这部分逻辑?
@Vector-SMG 你说的很对, 会考虑你的建议.