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

Android线程间通信的Message机制

 2010-06-01 15:44:00 来源:WEB开发网   
核心提示:213. }214. else {215. mOwnLooperThreadHandler = new EventHandler(myLooper);216. obj = "This is from OwnLooperThread self and handleMessage function execute

213. }

214. else {

215. mOwnLooperThreadHandler = new EventHandler(myLooper);

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

217. }

218. mOwnLooperThreadHandler.removeMessages(0);

219. //给自己发送消息

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

221. mOwnLooperThreadHandler.sendMessage(m);

222. Looper.loop();

223. }

224. }

225.

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

227. class ReceiveMessageThread extends Thread{

228. public void run() {

229. Looper.prepare();

230. mOtherThreadHandler = new Handler(){

231. public void handleMessage(Message msg) {

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

233. }

234. };

235. Looper.loop();

236. }

237. }

238.

239. }

package com.android.messageexample;

import android.app.Activity;

import android.content.Context;

import android.graphics.Color;

import android.os.Bundle;

import android.os.Handler;

import android.os.Looper;

import android.os.Message;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.TextView;

public class MessageExample extends Activity implements OnClickListener {

private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;

private final int FP = LinearLayout.LayoutParams.FILL_PARENT;

public TextView tv;

private EventHandler mHandler;

上一页  6 7 8 9 10 11 12 13 14 15 16  下一页

Tags:Android 线程 通信

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接