How to run a Runnable thread in Android?
来源:互联网 发布:java web开发流程 编辑:程序博客网 时间:2024/06/03 17:43
The simple fix to your example is:
final Runnable r = new Runnable()
{
public void run()
{
tv.append("Hello World");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
Or we can use normal thread for example (with original Runner):
Thread thread = new Thread()
{
@Override
public void run() {
try {
while(true) {
sleep(1000);
handler.post(r);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
You may consider your runnable object just as a command that can be sent to the message queue for execution, and handler as just a helper object used to send that command.
More details are here http://developer.android.com/reference/android/os/Handler.html
- How to run a Runnable thread in Android?
- How to run a script in ubuntu?
- How to Run CodedUI TestMethod in customized thread
- How to write mutiple graphs in a run in tensorflow
- How to run a .BAT file in InstallShield?
- How to: Run Partially Trusted Code in a Sandbox
- How to: Run Partially Trusted Code in a Sandbox
- How to run a _BAT file in InstallShield
- How to Run a Program in Compatibility Mode
- How to run test cases in a specified file?
- How to: Set a Thread Name in Native Code
- How to manage a Thread IN ASP.NET
- How to stop a NSThread sub-thread in iphone
- how to create a thread in win32 platform
- How to have a native thread in java
- How to run a jar
- how to run an android emulator in ubuntu 14.04
- How to Stop a Thread
- 在Struts 2中实现文件上传
- python3与python2代码差别
- j2me学习笔记【11】——捕获和处理按键编码
- VFS之super_block
- ASP.NET程序中常用的事件处理
- How to run a Runnable thread in Android?
- Ubuntu 10.04环境搭建android驱动开发环境
- 查看jar版本
- linux 下的 ftp + jdk + tomcat + apache +mysql
- 一个小公司老板的日常管理,希望能让创业的朋友学到东西
- 哇呵
- 恢复Ubuntu 9.10 GRUB引导的方法适用于10.04
- plsql 语法
- 程序人生之三 software VS world