Pareshが正しい!例を見てください...
private class SessionTask extends AsyncTask<String, Integer, Integer> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(TestUI.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setTitle("UploadFile");
dialog.setMessage("Uploading file...");
dialog.setCancelable(false);
dialog.setProgress(0);
dialog.show();
}
@Override
protected Integer doInBackground(String... params) {
.........
} catch(MalformedURLException e) {
Log.e(TestUI.TAG, "E: Malformed URL! " + e.getLocalizedMessage());
return 1;
} catch(IOException e) {
Log.e(TestUI.TAG, "E: I/O error! " + e.getLocalizedMessage());
return 2;
}
return 0;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
dialog.setMax(values[1]);
dialog.setProgress(values[0]);
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
dialog.dismiss();
switch (result) {
case 0:
Toast.makeText(TestUI.this, "Uploading finished", Toast.LENGTH_LONG).show();
new DownloadTask().execute(new String[] {TestUI.LINK_DOWN, TestUI.FILE_DOWN});
break;
case 1:
Toast.makeText(TestUI.this, "E: Malformed URL!", Toast.LENGTH_LONG).show();
break;
case 2:
Toast.makeText(TestUI.this, "E: I/O error! Connection was dismissed!!!", Toast.LENGTH_LONG).show();
break;
}
}
}