WEB开发网
开发学院手机开发Android 开发 Android线程间通信的Message机制 阅读

Android线程间通信的Message机制

 2010-06-01 15:44:00 来源:WEB开发网   
核心提示:obj = "OwnLooperThread has no looper and handleMessage function executed in main thread!";}else {mOwnLooperThreadHandler = new EventHandler(myLooper);

obj = "OwnLooperThread has no looper and handleMessage function executed in main thread!";

}

else {

mOwnLooperThreadHandler = new EventHandler(myLooper);

obj = "This is from OwnLooperThread self and handleMessage function executed in NoLooperThread!";

}

mOwnLooperThreadHandler.removeMessages(0);

//给自己发送消息

Message m = mOwnLooperThreadHandler.obtainMessage(3, 1, 1, obj);

mOwnLooperThreadHandler.sendMessage(m);

Looper.loop();

}

}

//ReceiveMessageThread has his own message queue by execute Looper.prepare();

class ReceiveMessageThread extends Thread{

public void run() {

Looper.prepare();

mOtherThreadHandler = new Handler(){

public void handleMessage(Message msg) {

Log.e(sTag, (String)msg.obj);

}

};

Looper.loop();

}

}

上一页  11 12 13 14 15 16 

Tags:Android 线程 通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接