- Java code
//获取好友分组的线程 new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Map<String, Object> params = new HashMap<String, Object>(); map = new HashMap<String, Object>(); friendGroup = new ArrayList<FriendGroup>(); friendList = new ArrayList<FriendGroup>(); params.put("ID", LoginActivity.userID); //获取用户组的输入流 InputStream group_is = WebServer.hcPostData("GetFriendGroup", "FriendApp.ashx", params); InputStream friends_is = WebServer.hcPostData("GetFriendList", "FriendApp.ashx", params); parser = new XMLParser(); try { friendGroup = parser.FriendGroupParser(group_is); friendList = parser.FriendGroupParser(group_is); Message message = new Message(); message.obj = friendGroup; mHandler.sendMessage(message); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); private Handler mHandler = new Handler() { @SuppressWarnings("unchecked") @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub friendGroup = (ArrayList<FriendGroup>) msg.obj; GetAllFriend(); super.handleMessage(msg); } };
这是我想到的,但是一个handler只能处理一个message啊!但是我有两个对象obj,一个FriendGroup,一个FriendList,只能处理一个怎么办呢?
------解决方案--------------------
加个
message.what = 1;
及
message.what = 2;
然后在
handleMessage
switch(msg.what)
{
case 1:
.....
break;
case 2:
.....
break;
}
------解决方案--------------------
定义两个消息,即what
- Java code
static final int SEND_GROUP = 1;static final int SEND_LIST = 2;