我正在使用 asy 任务来执行加载过程,而服务应该负责连接。我在线上遇到了一些错误:
serviceIntent.putExtra("receiver",new DownloadReceiver(new Handler()));
当我使用 AsyncTask 和服务进行连接时。我的 AsyncTask 代码是:
private class DownloadReceiver extends ResultReceiver{
public DownloadReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
// if (resultCode == DownloadService.UPDATE_PROGRESS) {
int progress = resultData.getInt("progress");
// mProgressDialog.setProgress(progress);
// if (progress == 100) {
// mProgressDialog.dismiss();
}
}
protected String doInBackground(String... params) {
Intent serviceIntent = new Intent();
serviceIntent.putExtra("url", "www.google.com");
new DownloadReceiver(new Handler());
serviceIntent.putExtra("receiver",new DownloadReceiver(new Handler()));
serviceIntent.setAction("connection.DownloadService");
context.startService(serviceIntent);
那么可能是什么问题?