TonnyL / PaperPlane

📚 PaperPlane - An Android reading app, including articles from Zhihu Daily, Guokr Handpick and Douban Moment.
Apache License 2.0
1.14k stars 277 forks source link

Cancel the network request in ondestroy() of the activity, should you consider it #26

Open cornucopib opened 6 years ago

TonnyL commented 6 years ago

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.

cornucopib commented 6 years ago

@TonnyL 在Activity或者fragment的onDestroy()的生命周期中,有可能当前界面中,还存在网络请求在执行,导致内存溢出或者空指针异常等等。所以取消网络请求是必要的,当前主流做法:1.如果网络请求中,用到rxjava,使用RxLifecycle来全局取消 2.使用ViewModel+LiveData来管理。是否考虑将其加入?完善这部分逻辑?

TonnyL commented 6 years ago

@Vector-SMG 你说的很对, 会考虑你的建议.