让我们说,我们从主UI线程开始一些线程。现在假设活动被停止或销毁。
onClick () { /* Activity onClickListener for some button */
new Thread (new MyThread (new Handler ())).start ();
}
private class MyThread implements Runnable {
Handler mUIHandler;
MyThread (Handler h) {
mUIHandler = h;
}
public void run () {
/* Long operation */
/* Post status update to UI */
Message msg = mUIHandler.obtainMessage ();
msg.obj = String.valueOf (statusCode);
mUIHandler.sendMessage (msg);
}
1)这些线程会发生什么?
2)从这些线程中,假设我将使用UI线程Handler对象向UI线程发布一些消息,那么那些UI更新会发生什么?