一,问题引入
异常: Only the original thread that created a view hierarchy can touch its views的解决方案
二,解决方案一
final Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what == 0)//成功
{
Log.d(TAG, "**********************start****************************");
playVideo(strVideoPath);//包含更新界面的方法
Log.d(TAG, "***********************end*****************************");
}
}
};
new Thread()
{
@Override
public void run()
{
// handler.post(runnableUi);
try{
Log.d(TAG, "######################start###############################");
handler.sendEmptyMessage(0);//UI线程外想更新UI线程
Log.d(TAG, "######################end###############################");
}
catch(Exception e)
{
Log.d(TAG, "***************************"+e.toString());
}
}
}.start();
三,解决方案二
Runnable runnableUi=new Runnable(){ @Override public void run() { //更新界面 textView.setText("the Content is:"+content); } }; new Thread(){ public void run(){ content=df.downLoadFiles(); handler.post(runnableUi); } }.start();
四,特别注意,引入函数包得时候,不要引入错误的包
import android.os.Handler; //这是正确的包
import java.util.logging.Handler;//不是这个包,而是上一个