UIthread UI 线程
来源:互联网 发布:ipad钢琴教学软件 编辑:程序博客网 时间:2024/04/30 05:04
The UIThread is the main thread of execution for your application. This is where most of your application code is run. All of your application components(Activities, Services, ContentProviders, BroadcastReceivers) are created in this thread, and any system calls to those applications are performed in this thread.
For instance, lets say your application is a single Activity class. Then all of the lifecycle methods and most of your event handling code is run in this UIThread. These are methods like OnCreate, OnPause, OnDestroy, OnClick, etc. Additionally, this is where all of the updates to the UI are made. Anything that causes the UI to be updated or changed HAS to happen on the UI thread.
For more info on your applications Processes and Threads click here.
When you explicitly spawn a new thread to do work in the background, this code is not is not run on the UIThread. So what happens if the this background thread needs to do something that changes the UI? This is what the runOnUiThread
is for. Actually you're supposed to use a Handler (see the link below for more info on this); it provides these background threads the ability to execute code that can modify the UI. They do this by putting the UI-modifying code in a Runnable object and passing it to the RunOnUiThread method.
For more info on spawning worker threads and updating the UI from them click here
I personally only use the RunOnUiThread method in my Instrumentation Tests. Since the test code does not execute in the UIThread, you need to use this method to run code that modifies the UI. So, I use it to inject click and key events into my application. I can then check the state of the application to make sure the correct things happened
For more info on testing and running code on the UIThread click here
- UIthread UI 线程
- android:Background线程池和UiThread线程池
- TimerTask中如何通过Handler交由UIThread更新UI
- UI线程
- UI线程
- UI线程
- workthread 和 UIthread
- UI线程、工作者线程
- 非UI线程更新UI!?
- Android UI线程和非UI线程
- Android UI线程和非UI线程
- Android UI线程和非UI线程
- Android UI线程和非UI线程
- 非UI线程更改UI线程1
- 非UI线程更改UI线程2
- 非UI线程更改UI线程3
- Android UI线程和非UI线程
- Android UI线程和非UI线程
- 每天一个linux命令(14):head 命令
- Android 判断SIM卡属于哪个移动运营商
- 复数类及各种操作(Java)
- 40款不容错过的个人摄影设计作品集网站
- Heat equation
- UIthread UI 线程
- 每天一个linux命令(15):tail 命令
- Javascript 中 apply() 和 call() 的区别
- 每天一个linux命令(16):which命令
- Access用OleDbParameter无法更新数据解决方案
- 家庭文件共享,FreeNas服务器的搭建过程
- 双卡手机,sim卡状态改变测试
- 使用CFindReplaceDialog
- Android 对Gallery的挖掘