小编Kje*_*der的帖子

Kotlin:runOnUiThread 未解决的参考

我正在尝试使用 Activity.runOnUiThread(Runnable),但 Android Studio 似乎认为该函数不存在。我已确保导入“android.app.Activity”。

我正在尝试使用线程连接到蓝牙设备并读取数据。我列出了已配对的设备,单击其中一个已配对的设备会将我带到第二个屏幕,然后我可以在其中连接/断开与所选设备的插座。连接和断开连接正常。

我现在尝试将数据流从 readThread 内部类发送回 UI 线程,但无法让 runOnUiThread 工作。无论我做什么,runOnUiThread 都无法被识别。

package com.example.idxdatalogger

import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothSocket
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import android.view.View
import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_second.*
import java.io.IOException
import java.io.InputStream
import java.util.*



class SecondActivity : AppCompatActivity() {
    var btAdapter: BluetoothAdapter? = null

    var data = arrayListOf<String>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        btAdapter = BluetoothAdapter.getDefaultAdapter()

        val position = (intent.getStringExtra("position"))!!.toInt()
        val uuid = UUID.fromString(intent.getStringExtra("UUID"))

        //textView.text = …
Run Code Online (Sandbox Code Playgroud)

scope kotlin android-studio

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

android-studio ×1

kotlin ×1

scope ×1