admin管理员组文章数量:1287840
In this example, I just want to get the HTML from Google and show it in my Screen. I have a loading screen, until the response arrived, so the Screen can be updated. The problem is, that the UI Screen updates 10 seconds late, even though the correct HTTP Response came already immediately. Also the invalidate function is correctly called, but has no immediate effect on the UI update.
override fun onGetTemplate(): Template {
if (currentTemplate != null) {
return currentTemplate!!
}
val contentRow = Row.Builder()
.setTitle(carContext.getString(R.string.loading))
.build()
val paneTemplate = PaneTemplate.Builder(
Pane.Builder()
.addRow(contentRow)
.build()
)
.setHeaderAction(Action.BACK)
.setTitle(carContext.getString(R.string.test))
.build()
currentTemplate = paneTemplate
fetchPrivacyPolicyContent()
return paneTemplate
}
private fun fetchContent() {
CoroutineScope(Dispatchers.IO).launch {
try {
val response = RetrofitClient.apiService.getGoogle()
if (response.isSuccessful) {
val htmlContent = response.body() ?: ""
withContext(Dispatchers.Main) {
val updatedRow = Row.Builder()
.setTitle(carContext.getString(R.string.test))
.addText(htmlContent)
.build()
val updatedPane = Pane.Builder()
.addRow(updatedRow)
.build()
currentTemplate = PaneTemplate.Builder(updatedPane)
.setHeaderAction(Action.BACK)
.setTitle(carContext.getString(R.string.test))
.build()
invalidate()
Log.e("ContentScreen", "TEST")
}
}
... } }
val apiService: ApiService by lazy {
Retrofit.Builder()
.baseUrl(";)
.addConverterFactory(ScalarsConverterFactory.create())
.build()
.create(ApiService::class.java)
}
Whatever I did, invalidate, push and pop the screen after response, nothing seems to work.
本文标签: Android Automotive Update UI Screen after CoroutineScope HTTP RequestStack Overflow
版权声明:本文标题:Android Automotive: Update UI Screen after CoroutineScope HTTP Request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741325618a2372461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论