上一页 1 ··· 49 50 51 52 53 54 55 56 57 ··· 202 下一页
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { suspend fun getResult1(): String { delay(3000L) // 模拟耗时操作 return "Result1" } suspe 阅读全文
posted @ 2025-07-26 11:38 刘宏缔的架构森林 阅读(28) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { suspend fun getResult1(): String { delay(1000L) // 模拟耗时操作 return "Result1" } suspe 阅读全文
posted @ 2025-07-26 11:38 刘宏缔的架构森林 阅读(43) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { val parentJob: Job var job1: Job? = null var job2: Job? = null var job3: Job? = nu 阅读全文
posted @ 2025-07-26 11:38 刘宏缔的架构森林 阅读(37) 评论(0) 推荐(0)
摘要: 一,代码: binding.button1.setOnClickListener { runBlocking { suspend fun download() { // 模拟下载任务 val time=3000L logX("模拟下载用时: = $time") delay(time) } val j 阅读全文
posted @ 2025-07-26 11:38 刘宏缔的架构森林 阅读(36) 评论(0) 推荐(0)
摘要: 一,代码: binding.button1.setOnClickListener { //先定义一个Int类的扩展函数 fun Int.square() = this * this //定义一个带接收器的lambda表达式 val squareFun: Int.()->Int = Int::squa 阅读全文
posted @ 2025-07-26 11:36 刘宏缔的架构森林 阅读(64) 评论(0) 推荐(0)
摘要: 一,代码: binding.button1.setOnClickListener { System.setProperty("kotlinx.coroutines.debug", "on") println("main线程开始:${Thread.currentThread().name}") run 阅读全文
posted @ 2025-07-19 07:47 刘宏缔的架构森林 阅读(62) 评论(0) 推荐(0)
摘要: 一,代码: binding.button1.setOnClickListener { println("sleep1 start,") // 协程已在等待时主线程还在继续 Thread.sleep(200L) // 阻塞主线程 0.2 秒钟 println("sleep1 end,") // 协程已 阅读全文
posted @ 2025-07-19 07:47 刘宏缔的架构森林 阅读(84) 评论(0) 推荐(0)
摘要: 一,代码: binding.button1.setOnClickListener { //启动debug模式,可以打印协程的编号 System.setProperty("kotlinx.coroutines.debug", "on") println("runBlocking外运行: ${Threa 阅读全文
posted @ 2025-07-19 07:47 刘宏缔的架构森林 阅读(66) 评论(0) 推荐(0)
摘要: 一,用runBlocking创建协程 1,代码: binding.button1.setOnClickListener { System.setProperty("kotlinx.coroutines.debug", "on") val count = AtomicInteger() val for 阅读全文
posted @ 2025-07-19 07:47 刘宏缔的架构森林 阅读(29) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件,创建一个假数据,保存到viewmodel binding.button1.setOnClickListener { //只有一个函数类型作为函数参数 fun highOrderFunction(operation: (Int, Int) -> Int): Int { 阅读全文
posted @ 2025-07-19 07:46 刘宏缔的架构森林 阅读(43) 评论(0) 推荐(0)
上一页 1 ··· 49 50 51 52 53 54 55 56 57 ··· 202 下一页