[英]For ActivityResultContracts, what is the alternative for In-App Updates?
[英]JobCancellationException with in-app updates
我注意到一些用戶在使用靈活的應用內更新時遇到問題, 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)
不幸的是,我不知道代碼的哪一部分導致了這個問題。 這是唯一與協程相關的代碼,留在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) {
}
}
}
我懷疑requestUpdateFlow()
中的代碼在協程作業已經取消並且我看不到確切的堆棧跟蹤時調用了offer
,因為 Play Core 庫被混淆了?
我正在使用以下版本的庫:
"com.google.android.play:core:1.7.2"
"com.google.android.play:core-ktx:1.7.0"
JobCancellationException: Job was cancelled
幾乎是在協程 scope 中的作業被取消的情況下拋出。
示例:用戶 go 到屏幕 a,在該屏幕中調用 api 以獲取某些內容。 但是當 api 未完成時,用戶按返回關閉此屏幕。 因此,當收到響應時,作業在 -> 異常之前取消。
要更多處理JobCancellationException
,您可以使用suspendCancellableCoroutine
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.