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

Android线程间通信的Message机制

 2010-06-01 15:44:00 来源:WEB开发网   
核心提示:复制到剪贴板 Java代码1. package com.android.messageexample;2. import android.app.Activity;3. import android.content.Context;4. import android.graphics.Color;5. import a

复制到剪贴板 Java代码

1. package com.android.messageexample;

2. import android.app.Activity;

3. import android.content.Context;

4. import android.graphics.Color;

5. import android.os.Bundle;

6. import android.os.Handler;

7. import android.os.Looper;

8. import android.os.Message;

9. import android.util.Log;

10. import android.view.View;

11. import android.view.View.OnClickListener;

12. import android.widget.Button;

13. import android.widget.LinearLayout;

14. import android.widget.TextView;

15. public class MessageExample extends Activity implements OnClickListener {

16. private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;

17. private final int FP = LinearLayout.LayoutParams.FILL_PARENT;

18. public TextView tv;

19. private EventHandler mHandler;

20. private Handler mOtherThreadHandler=null;

21. private Button btn, btn2, btn3, btn4, btn5, btn6;

22. private NoLooperThread noLooerThread = null;

23. private OwnLooperThread ownLooperThread = null;

24. private ReceiveMessageThread receiveMessageThread =null;

25. private Context context = null;

26. private final String sTag = "MessageExample";

27. private boolean postRunnable = false;

28.

29. /** Called when the activity is first created. */

30. @Override

31. public void onCreate(Bundle savedInstanceState) {

32. super.onCreate(savedInstanceState);

33. context = this.getApplicationContext();

34. LinearLayout layout = new LinearLayout(this);

35. layout.setOrientation(LinearLayout.VERTICAL);

36. btn = new Button(this);

37. btn.setId(101);

38. btn.setText("message from main thread self");

上一页  1 2 3 4 5 6 7 8 9 10 11  下一页

Tags:Android 线程 通信

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