在Android的处理程序,尺蠖实施 [英] Handler-Looper implementation in Android

查看:104
本文介绍了在Android的处理程序,尺蠖实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 在我有一个处理程序(UI线程)活动
  2. 在我开始新的主题,使handler.post(新MyRunnable()) - (新的工作线程)

Android的文档中的有关方法后说:导致了Runnable r以被添加到消息队列中的可运行将是此处理器相连接的线程上运行。

处理器连接到UI线程。 如何机器人可以运行可运行在没有新的线程创建相同的UI线程?

时的新的线程将使用从handler.post Runnable接口创建()? 或者它只是run()方法将从Runnable的子类叫什么名字?

解决方案
  

处理器连接到UI线程。

正确的。

  

如何机器人可以运行可运行在同一个UI线程没有新的线程创建?

任何线程,包括主应用程序(UI)线程,可以调用后()在处理程序(或任何查看,对于这个问题)。

  1. I have Activity with Handler (UI thread)
  2. I start new Thread and make handler.post(new MyRunnable()) - (new work thread)

Android documentation said about post method: "Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached."

Handler attached to UI thread. How android can run runnable in the same UI thread without new thread creation?

Is new thread will be created using Runnable from handler.post()? Or it's only run() method will be called from Runnable subclass?

解决方案

Handler attached to UI thread.

Correct.

How android can run runnable in the same UI thread without new thread creation?

Any thread, including the main application ("UI") thread, can call post() on Handler (or on any View, for that matter).

这篇关于在Android的处理程序,尺蠖实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆