handler 消息处理器:用于发送、接收消息
主线程中更新UI1
2
3
4
5
6
7
8
9
10
11Handler handler=new Handler(){
public void handleMessage(Message msg){
super.handleMessage(msg);
switch(msg.what){
case SUCCESS:
break;
default:
break
}
}
};
子线程向消息池发送消息1
2
3
4
5
6
7
8new Thread(new Runnable(){
public void run(){
Message msg=new Message();
msg.what=0;
msg.obj=要操作的变量;
handler.sendMessage(msg);
}
}).start();
get请求
1 | HttpURLConnection conn = null; |
图片缓存
1 | String urlString = ""; |
post请求
1 | new Thread(new Runnable(){ |
编码问题
将汉字转为以%开头的字符串1
URLEncoder.encode(editText.getString(), "utf-8");
采用iso8859-1编码对姓名进行逆转,转成字节数组,再使用utf-8对数据编码1
username=new String(username.getBytes("iso8859-1"),"utf-8");