Android---手动创建线程与GUI线程同步的第三种方法:
在GUI线程中调用runOnUiThread(Runnable runnable), 此时work Thread与GUI线程在同一个线程中, 所以,可以直接在work thread中更改GUI中的UI(此方法比较简单,适合work thread执行的任务比较简单,不耗进的任务。特别注意:当work thread 执行比较耗时的任务时,使用此方法会阻塞GUI线程,因为work thread 实际上也是在GUI线程中运行的)
1>布局与上二节都一样
1.1>效果如下:
1.2>代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.cxc.threadandhandler.MainActivity" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="wor