handle 之 白日依山近
来源:互联网 发布:数据挖掘专业考研 编辑:程序博客网 时间:2024/04/29 01:43
package com.test.myhandleractivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private MyHandler myhandler = new MyHandler();
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
MyThread mythread=new MyThread();
new Thread(mythread).start();
MyThreadtwo mytwo=new MyThreadtwo();
new Thread(mytwo).start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class MyHandler extends Handler{
public MyHandler() {
}
public MyHandler(Looper L) {
super(L);
}
public void handleMessage (Message msg){
Log.d("MyHandler","handleMessage...");
super.handleMessage(msg);
Bundle b =msg.getData();
String tag = b.getString("color");
if(tag.equals("ab")){
MainActivity.this.button.setText("fuck cellon");
}
if(tag.equals("ba")){
MainActivity.this.button.setText("cellon dustbin fuck");
}
}
}
class MyThread implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("thread...", "mThread....");
Message msg =new Message();
Bundle b=new Bundle();
b.putString("color", "ba");
// b.putString("tag", "thread1");
msg.setData(b);
MainActivity.this.myhandler.sendMessage(msg);
}
}
class MyThreadtwo implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("thrad..", "mThread");
Message msg =new Message();
Bundle bundle=new Bundle();
bundle.putString("color","ab");
// bundle.putString("tag", "thread2");
msg.setData(bundle);
MainActivity.this.myhandler.sendMessage(msg);
}
}
}
- handle 之 白日依山近
- vc++之handle
- windows handle之DuplicateHandle
- Android入门之Handle
- Android学习之Handle
- jbd 之 handle
- 设计模式之--单例模式【小白日记】
- 小白日记:机器学习算法之决策树算法
- C++之 typedef void *HANDLE
- 线程通信之handle用法
- handle
- HANDLE
- handle
- Handle
- handle
- handle
- handle
- Handle
- java.lang.OutOfMemoryError: Java heap space
- ffmpeg水印制作
- Data Structures (Weiss) Chapter 6: Binary Heap, Priority Queue
- JS中计算字符串的长度
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- handle 之 白日依山近
- 《LINUX3.0内核源代码分析》第二章:中断和异常(3)
- 第一篇
- Foglight 监控 weblogic 10.3 NodeManager 的配置方法
- Fragment activity
- 《LINUX3.0内核源代码分析》第二章:中断和异常(4)
- 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
- JDBC入门
- Hibernate常见映射关系总结