Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么手动取消网络请求,或是在按手机返回键时取消网络请求 #3

Open
chenyacheng opened this issue Sep 13, 2021 · 6 comments

Comments

@chenyacheng
Copy link

No description provided.

@ldlywt
Copy link
Owner

ldlywt commented Sep 14, 2021

viewmodel在Activity销毁时不会导致内存泄露的

@chenyacheng
Copy link
Author

viewmodel在Activity销毁时不会导致内存泄露的

这个我知道。我是想,当请求过程中,弹出dialog,但我手动按手机返回键,取消掉dialog,顺便也终止网络请求。不知道这个怎么搞

@ljphawk
Copy link

ljphawk commented Jun 15, 2022

看了看可以修改launchFlow方法,使用onEach和launchIn操作符,返回job对象,取消的时候调用job.cancel

@ruirui1128
Copy link

ruirui1128 commented Sep 22, 2022

如果在这个项目中要实现这个功能,需要在封装一些功能。
实现的原理是,在dialog cancel 的时候,手动将job.cancel。

@huadongliang-tal
Copy link

UNKNOWN_ERROR:kotlinx.coroutines.JobCancellationException: Job was cancelled; job=SupervisorJobImpl{Cancelling}@a277d95msgJob was cancelledname:JobCancellationException 取消会报异常

@huadongliang-tal
Copy link

UNKNOWN_ERROR:kotlinx.coroutines.JobCancellationException: Job was cancelled; job=SupervisorJobImpl{Cancelling}@a277d95msgJob was cancelledname:JobCancellationException 取消会报异常
大家怎么处理的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants