if (result != null) {
Message msg = handler.obtainMessage();
msg.what = Constant.GETMSG;
msg.obj = result;
handler.sendMessage(msg);
} else {
Message msg = handler.obtainMessage();
msg.what = Constant.ERRORREPORTSHOW;
msg.obj = "暂时无法获取数据";
handler.sendMessage(msg);
}
从上面的类中传出数据然后利用下面的代码接收发送的数据
private Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
if (msg.what == Constant.GETMSG)
{
(result数据类型) data = (result数据类型) msg.obj;
}
else if (msg.what == Constant.ERRORREPORTSHOW)
{
String errorinfo = String.valueOf((String) msg.obj);
Utils.show(Activity.this, errorinfo);
}
else
{
}
}
}
避免使用全局变量带来的麻烦