我正在使用asy任務來執行加載過程,而服務應該注意連接。 我正在上線的一些錯誤:錯誤Intent.putExtra AsyncTask
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);
有啥可問題?
發佈錯誤給出的堆棧跟蹤。還可以詳細說明你想要達到的目標嗎?你爲實際嘗試做的事情提供了很少的背景。 – FoamyGuy
給我們看堆棧跟蹤 – confucius
你爲什麼要嘗試啓動一個'Service'來從'AsyncTask'的工作線程執行下載?這沒有意義。可以在'doInBackground()'中執行下載,或者直接從主「Activity」代碼啓動「Service」。 – Squonk