<pre name="code" class="java">package com.tl.thread;
import java.io.IOException;
import java.util.Map;
import android.os.Handler;
import com.tl.handler.callback.CallBackI;
public class PostThread extends Thread{
private String url;
private Map<String,String> paramMap;
private CallBackI handler;
public PostThread(String url,Map paramMap,CallBackI handler){
this.url=url;
this.paramMap=paramMap;
this.handler=handler;
}
public void doTask(){
try{
String json = UploadDataUtil.post(url , paramMap);
handler.doTask(json);
}catch(Exception e){
}
}
public void run(){
doTask();
}
}
继承Thread类
public interface CallBackI {
public void doTask(String json);
}
回调接口
PostThread postThrad = new PostThread(CommonData.url_getGeRenInfo, paramMap, new CallBackI() {
@Override
public void doTask(String json) {
try {
通过回调类处理从请求中得到的json数据;
} catch (Exception e) {
e.printStackTrace();
}
}
});
postThrad.start();