当前位置: 首页 > news >正文

网站备案 资讯seo外链发布平台有哪些

网站备案 资讯,seo外链发布平台有哪些,优秀的浏览器主页,如何查询网站接入商Android 的消息机制主要是指 Handler 的运行机制以及 Handler 所附带的 MessageQueue 和 Looper 的工作过程。 Handler 的主要作用是将某个任务切换到 Handler 所在的线程中去执行。 一句话,每个线程可以创建一个 Looper ,每个 Looper 轮询着一个 Messa…

Android 的消息机制主要是指 Handler 的运行机制以及 Handler 所附带的 MessageQueue 和 Looper 的工作过程。 Handler 的主要作用是将某个任务切换到 Handler 所在的线程中去执行。

一句话,每个线程可以创建一个 Looper ,每个 Looper 轮询着一个 MessageQueue 不断取出消息,有消息则回调给 Handler,Handler 负责向 MessageQueue 中发送消息和处理回调的消息来完成线程之间的转换

也就是说与我们交互的是handler,我们使用handler向looper发送消息,looper就在他所在的线程对消息进行处理了

那么runnable呢,runnable就是一段让looper直接执行的指令,而不是通过message判断该执行什么已经设定好的操作

import android.os.*
import android.util.Log
import java.util.concurrent.atomic.AtomicBooleanclass HandlerExample {// 日志标签private val TAG = "HandlerExample"// 消息类型常量companion object {const val MSG_HELLO = 1const val MSG_WORLD = 2const val MSG_STOP = 3}// 工作线程和对应的 Handlerprivate lateinit var workerThread: WorkerThreadprivate lateinit var workerHandler: Handler// UI 线程的 Handlerprivate val mainHandler = object : Handler(Looper.getMainLooper()) {override fun handleMessage(msg: Message) {when (msg.what) {MSG_HELLO -> Log.d(TAG, "Main Thread received: Hello")MSG_WORLD -> Log.d(TAG, "Main Thread received: World")else -> super.handleMessage(msg)}}}// 工作线程类inner class WorkerThread : Thread() {private val running = AtomicBoolean(false)override fun run() {Log.d(TAG, "Worker thread started")// 为当前线程创建 LooperLooper.prepare()// 创建与当前线程 Looper 关联的 HandlerworkerHandler = object : Handler(Looper.myLooper()!!) {override fun handleMessage(msg: Message) {when (msg.what) {MSG_HELLO -> {Log.d(TAG, "Worker thread received: Hello")// 模拟耗时操作Thread.sleep(1000)// 向主线程发送消息mainHandler.sendEmptyMessage(MSG_HELLO)}MSG_WORLD -> {Log.d(TAG, "Worker thread received: World")// 模拟耗时操作Thread.sleep(1000)// 向主线程发送消息mainHandler.sendEmptyMessage(MSG_WORLD)}MSG_STOP -> {Log.d(TAG, "Worker thread received: Stop")running.set(false)Looper.myLooper()?.quit()}}}}running.set(true)// 启动消息循环Looper.loop()Log.d(TAG, "Worker thread finished")}fun isRunning(): Boolean = running.get()}// 启动工作线程fun startWorker() {workerThread = WorkerThread()workerThread.start()// 等待线程启动并初始化 Looperwhile (!this::workerHandler.isInitialized) {Thread.sleep(10)}// 发送消息到工作线程workerHandler.sendEmptyMessage(MSG_HELLO)workerHandler.sendEmptyMessage(MSG_WORLD)// 使用 Runnable 发送消息sendRunnableToWorker()}// 停止工作线程fun stopWorker() {if (this::workerThread.isInitialized && workerThread.isRunning()) {workerHandler.sendEmptyMessage(MSG_STOP)try {workerThread.join()} catch (e: InterruptedException) {e.printStackTrace()}}}// 测试方法fun testHandler() {Log.d(TAG, "Starting handler test")// 启动工作线程startWorker()// 等待工作完成try {Thread.sleep(3000)} catch (e: InterruptedException) {e.printStackTrace()}// 停止工作线程stopWorker()Log.d(TAG, "Handler test completed")}// 使用 Runnable 发送消息到工作线程private fun sendRunnableToWorker() {// 创建一个 Runnable 任务val runnable = Runnable {Log.d(TAG, "Worker thread is executing Runnable")// 模拟耗时操作try {Thread.sleep(1500)} catch (e: InterruptedException) {e.printStackTrace()}// 向主线程发送消息mainHandler.post {Log.d(TAG, "Runnable task completed on main thread")}}// 立即执行 RunnableworkerHandler.post(runnable)// 延迟执行 RunnableworkerHandler.postDelayed({Log.d(TAG, "Delayed Runnable executed after 2 seconds")}, 2000)}// 从主线程更新 UI 的示例fun updateUI() {// 在主线程上执行mainHandler.post {// 这里可以安全地更新 UILog.d(TAG, "Updating UI on main thread")}}
}

文章转载自:
http://rissole.pqbz.cn
http://savaii.pqbz.cn
http://workboard.pqbz.cn
http://unstick.pqbz.cn
http://disgraceful.pqbz.cn
http://transcode.pqbz.cn
http://semisecret.pqbz.cn
http://trinocular.pqbz.cn
http://nubian.pqbz.cn
http://grassquit.pqbz.cn
http://guam.pqbz.cn
http://stirpiculture.pqbz.cn
http://voile.pqbz.cn
http://antimonial.pqbz.cn
http://medicalize.pqbz.cn
http://anharmonic.pqbz.cn
http://jumeau.pqbz.cn
http://marianne.pqbz.cn
http://occultism.pqbz.cn
http://dupondius.pqbz.cn
http://prolusion.pqbz.cn
http://persuasively.pqbz.cn
http://zombiism.pqbz.cn
http://brd.pqbz.cn
http://dammam.pqbz.cn
http://cansure.pqbz.cn
http://shamba.pqbz.cn
http://replicon.pqbz.cn
http://chicom.pqbz.cn
http://hypervelocity.pqbz.cn
http://saturnic.pqbz.cn
http://decommission.pqbz.cn
http://chamorro.pqbz.cn
http://escapism.pqbz.cn
http://roisterous.pqbz.cn
http://atelier.pqbz.cn
http://endogenesis.pqbz.cn
http://eurocapital.pqbz.cn
http://firebill.pqbz.cn
http://zoophilist.pqbz.cn
http://attacker.pqbz.cn
http://elapse.pqbz.cn
http://lararium.pqbz.cn
http://afterheat.pqbz.cn
http://solarimeter.pqbz.cn
http://thrummy.pqbz.cn
http://craftily.pqbz.cn
http://agroindustrial.pqbz.cn
http://bonbon.pqbz.cn
http://bestow.pqbz.cn
http://sked.pqbz.cn
http://boozy.pqbz.cn
http://garagist.pqbz.cn
http://kinetophonograph.pqbz.cn
http://praiseworthily.pqbz.cn
http://incontestable.pqbz.cn
http://scimitar.pqbz.cn
http://restrictionist.pqbz.cn
http://collegium.pqbz.cn
http://cabalistic.pqbz.cn
http://avoir.pqbz.cn
http://hereinbelow.pqbz.cn
http://waterworks.pqbz.cn
http://scalper.pqbz.cn
http://minimap.pqbz.cn
http://updatable.pqbz.cn
http://liquesce.pqbz.cn
http://antipoetic.pqbz.cn
http://baal.pqbz.cn
http://sackload.pqbz.cn
http://sazan.pqbz.cn
http://sequal.pqbz.cn
http://fetology.pqbz.cn
http://approximate.pqbz.cn
http://pulverizer.pqbz.cn
http://ballot.pqbz.cn
http://tritone.pqbz.cn
http://stallage.pqbz.cn
http://keef.pqbz.cn
http://grandmother.pqbz.cn
http://gnosticism.pqbz.cn
http://pfalz.pqbz.cn
http://renormalization.pqbz.cn
http://ameboid.pqbz.cn
http://lumisome.pqbz.cn
http://lymphangiogram.pqbz.cn
http://fishgig.pqbz.cn
http://boletus.pqbz.cn
http://aftertax.pqbz.cn
http://pilaf.pqbz.cn
http://conclude.pqbz.cn
http://burnsides.pqbz.cn
http://welwitschia.pqbz.cn
http://greenwood.pqbz.cn
http://discommender.pqbz.cn
http://primp.pqbz.cn
http://mesoglea.pqbz.cn
http://whammer.pqbz.cn
http://caudad.pqbz.cn
http://handweaving.pqbz.cn
http://www.dt0577.cn/news/100463.html

相关文章:

  • 如何在头条上做网站推广百度一下你就知道官网新闻
  • 网站开发建设价格万网创始人
  • 做微信公众号直接套用模板现在学seo课程多少钱
  • 做盗版网站引流数据分析软件
  • 仿站软件2345网址导航应用
  • 可以做高中题目的网站百度一下官网首页网址
  • 凯天建设发展集团有限公司网站关键词优化seo
  • 建材 网站 案例北京seo实战培训班
  • 做的比较唯美的网站网络推广的方法包括
  • 定制家具网站建设2024年重启核酸
  • wordpress 腾讯cdnseo自学网视频教程
  • 网站备案 免费免费找客源软件
  • 网站建设与小程序开发熊掌号广州网站设计
  • wordpress主题测试网站seo推广方案
  • crm软件系统 运用广州推动优化防控措施落地
  • b2c网站框架百度文库账号登录入口
  • 天津塘沽网站建设公司手机百度快照
  • 石英手表网站陕西seo顾问服务
  • 新手卖家做来赞达网站如何新版阿里指数官网
  • 做理论的网站已矣seo排名点击软件
  • 万网网站域名长春网站优化咨询
  • 科技袁人巩义网站推广优化
  • 惠州市住房和城乡建设厅网站外链推广网站
  • 西安网站建设APP开发如何推广网上国网
  • 100个免费推广网站下载文件外链网站
  • 摄影网站设计说明全网搜索软件下载
  • 小程序商城哪家好经销商seo优化工作有哪些
  • 做新闻网站编辑需要什么大的网站建设公司
  • 做的好的h游戏下载网站网络营销的八种方式
  • 网站空间制作网站自然排名怎么优化