WEB开发网
开发学院手机开发Android 开发 Android的HTTP通信 XML解析和异步消息处理 阅读

Android的HTTP通信 XML解析和异步消息处理

 2010-02-03 19:10:00 来源:WEB开发网   
核心提示:// 发送消息mHandler.sendMessage(msg);}private void sendMessage(int what) {Message msg = mHandler.obtainMessage(what);mHandler.sendMessage(msg);}private void sendMes

// 发送消息

mHandler.sendMessage(msg);

}

private void sendMessage(int what) {

Message msg = mHandler.obtainMessage(what);

mHandler.sendMessage(msg);

}

private void sendMessage(int what, int arg1, int arg2) {

Message msg = mHandler.obtainMessage(what, arg1, arg2);

mHandler.sendMessage(msg);

}

private static final int FILE_DOWNLOAD_CONNECT = 0;

private static final int FILE_DOWNLOAD_UPDATE = 1;

private static final int FILE_DOWNLOAD_COMPLETE = 2;

private static final int FILE_DOWNLOAD_ERROR = -1;

// 自定义的 Handler

private class EventHandler extends Handler {

private DownloadManagerAsync mManager;

public EventHandler(DownloadManagerAsync manager) {

mManager = manager;

}

// 处理接收到的消息

@Override

public void handleMessage(Message msg) {

switch (msg.what) {

case FILE_DOWNLOAD_CONNECT:

if (mOnDownloadConnectListener != null)

mOnDownloadConnectListener.onDownloadConnect(mManager);

break;

case FILE_DOWNLOAD_UPDATE:

if (mOnDownloadUpdateListener != null)

mOnDownloadUpdateListener.onDownloadUpdate(mManager,

msg.arg1);

break;

case FILE_DOWNLOAD_COMPLETE:

if (mOnDownloadCompleteListener != null)

mOnDownloadCompleteListener.onDownloadComplete(mManager,

msg.obj);

break;

case FILE_DOWNLOAD_ERROR:

if (mOnDownloadErrorListener != null)

mOnDownloadErrorListener.onDownloadError(mManager,

(Exception) msg.obj);

break;

default:

break;

}

}

}

// 定义连接事件

private OnDownloadConnectListener mOnDownloadConnectListener;

上一页  4 5 6 7 8 9 10 11  下一页

Tags:Android HTTP 通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接