How to run a Runnable thread in Android?
2011-02-10 15:16
302 查看
The simple fix to your example is:
Or we can use normal thread for example (with original Runner):
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
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 CodedUI TestMethod in customized thread
- How to run Android apps in tablet mode on your phone
- how to run an android emulator in ubuntu 14.04
- How to Build and Run Android L 64-bit ARM in QEMU
- How to run custom rule in Android.mk before compilation?
- How to edit the init.rc in android
- FFmpeg Understanding(4. How to compile and run testing files utilizing FFMPEG in VC?)
- How to Run a Program in Compatibility Mode
- how to use greendao in android studio
- How to disable gradle 'offline mode' in android studio?
- how to run tempest in devstack within vmware workstation
- How to Use FontAwesome in an Android App(把 icons 变得和 text 一样)
- How to terminate a thread in Java
- HOW TO SET UP ADB (ANDROID DEBUG BRIDGE) IN MAC OSX
- How to run a .BAT file in InstallShield?
- Ex2010-19 How to Run the Exchange Management Shell EMS in PowerShell
- Android从源码分析handler.post(runnable),view.post(runnable),runOnUiThread(runnable)执行时机
- How .NET run-time determines which member to invoke in a interface involving hiearchy
- How .NET run-time determines which member to invoke in a interface involving hiearchy
- android中的runOnUiThread(runnable)