【发布时间】:2021-01-13 10:13:12
【问题描述】:
我有 MainActivity 和 MyService 类。在服务中,我与服务器连接,但我还需要更新一些 UI,我需要 MainActivity 的上下文。更准确地说,我需要使用 layoutInflater 然后更新视图。这应该分开做吗? 一个函数的例子
private suspend fun setStations(serverText: String) {
withContext(Main) {
for (i in (1..numStations(serverText)))
{
frame = ScrollView( ) //would need context here
layoutInflater.inflate(R.layout.frame_layout, frame)
.
.
.
【问题讨论】:
标签: android kotlin service android-context