0
我想確定我runnable
在我的主線程,然後將其作爲參數傳遞到另一個線程像下面 -執行可運行的參數在自定義線程類
final Runnable runnable = new Runnable() {
@Override
public void run() {
Log.i("Running runnable","");
}
};
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
text.setText(msg.obj.toString());
}
};
ThreadTest handlerThreadTest = new ThreadTest(runnable, handler);
handlerThreadTest.start();
的ThreadTest
類定義如下 -
public class ThreadTest extends Thread {
private Handler handler;
private Runnable runnable;
public ThreadTest(Runnable runnable, Handler handler) {
this.handler = handler;
this.runnable = runnable;
}
@Override
public void run() {
super.run();
runnable.run();
Message msg = handler.obtainMessage();
msg.obj = "YUSSSSSS!";
handler.sendMessage(msg);
} }
我能夠發送「YUSSSSSS」消息給我的處理程序,但runnable.run()
似乎並不奏效,因爲我什麼也看不到在logcat中。
我在哪裏弄錯了?