[英]JobCancellationException with in-app updates
I've noticed that some of the users have issues to use flexible in-app update, the JobCancellationException: Job was cancelled
is thrown with incomprehensible stack trace:我注意到一些用户在使用灵活的应用内更新时遇到问题,
JobCancellationException: Job was cancelled
抛出了难以理解的堆栈跟踪:
at dalvik.system.VMStack.getThreadStackTrace(VMStack.java)
at java.lang.Thread.getStackTrace(Thread.java:1538)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
Unfortunately, I don't which part of the code is causing the issue.不幸的是,我不知道代码的哪一部分导致了这个问题。 This is the only coroutine related code, staying in
MyViewModel
:这是唯一与协程相关的代码,留在
MyViewModel
中:
init {
viewModelScope.launch {
try {
appUpdateManager.requestUpdateFlow().collect { appUpdateResult ->
// Do something with result.
}
} catch (e: InstallException) {
// Do something with an error.
}
}
}
fun requestUpdate(fragment: Fragment) {
viewModelScope.launch {
try {
val appUpdateInfo = appUpdateManager.requestAppUpdateInfo()
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
fragment,
REQUEST_CODE
)
} catch (e: IntentSender.SendIntentException) {
}
}
}
I suspect that code inside requestUpdateFlow()
is calling offer
while the coroutine job is already cancelled and I can't see the exact stacktrace, because Play Core library is obfuscated?我怀疑
requestUpdateFlow()
中的代码在协程作业已经取消并且我看不到确切的堆栈跟踪时调用了offer
,因为 Play Core 库被混淆了?
I'm using following versions of the libraries:我正在使用以下版本的库:
"com.google.android.play:core:1.7.2"
"com.google.android.play:core-ktx:1.7.0"
JobCancellationException: Job was cancelled
is thrown in almost case is job in coroutine scope is cancelled. JobCancellationException: Job was cancelled
几乎是在协程 scope 中的作业被取消的情况下抛出。
Example: User go to a screen a in which call api to get something.示例:用户 go 到屏幕 a,在该屏幕中调用 api 以获取某些内容。 But user press back to close this screen while api not complete.
但是当 api 未完成时,用户按返回关闭此屏幕。 Thus, when receive response, job cancelled before -> exception.
因此,当收到响应时,作业在 -> 异常之前取消。
To more handle JobCancellationException
you can using suspendCancellableCoroutine
.要更多处理
JobCancellationException
,您可以使用suspendCancellableCoroutine
。
More detail: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html更多详细信息: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.ZFC369E88D5FC2769
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.