java 线程

线程一
class LoginThread extends Thread{
public void StartThread() {
Thread a = new Thread(this);
a.start();
}
@Override
public void run() {
try {
sleep(1000);
Login();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

使用
LoginThread lt =new LoginThread();
lt.StartThread();
线程二

public class MyRunnable implements Runnable{
public void run(){

}
}

使用

Thread thread=new Thread(new MyRunnable());
thread.start();

线程三
Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 3:

break;
case 1:
//createNotification(1);
break;
case 2:
StopLoading();
Alerts("下载出错,请稍后再试");
break;
}
}
};

使用
myHandler.sendEmptyMessage(2);

或者
Message message = new Message();
Bundle boBundle = new Bundle();
boBundle.putString("Title", "系统提示");
boBundle.putString("Msg", "检测到系统有新版本,是否更新");
message.setData(boBundle);
message.what=3;
myHandler.sendMessage(message);
线程四

private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
SetAdapter(); //有数据
return null;
}
}

使用

AsyncCallWS task = new AsyncCallWS();
task.execute();

 

 

posted @ 2014-04-21 15:52  文艺流浪汉  阅读(166)  评论(0编辑  收藏  举报