AsyncTask for multiple operations and using onProgressUpdate as a UI message dispatcher
===

I'm trying to write some code to perform multiple and sequential calls to a webservice. The result of each of them is used in some logic, so I can't just run them all one after another, and I'm also updating the UI to inform the user about what's going on, so I thought that an `AsyncTask` was the answer to my question.

My problem is that I feel like I'm using it in the wrong way (code below). Should I have written safer/better/stricter code and queued one AsyncTask after another? Or should I have used plain old `new Thread()`'s and `View.post()`'s?

This is the code:

        private class AsyncDownload extends AsyncTask<Void, Object, Void> {
	private final static int DONE = 0, SESSION = 1, LIST = 2, ITEM = 3;

	@Override
	protected void onPreExecute() {
	    tvStatus.setText("Downloading...");
	    progress.setProgress(0);
	    progress.setVisibility(View.VISIBLE);
	}

	private GregorianCalendar currentServerTime;

	@Override
	protected Void doInBackground(Void... params) {
	    boolean sessionOpened = WSWrapper.openSession();
	    if (!sessionOpened) {
		boolean accountOk = WSWrapper.login();
		if (accountOk) {
		    publishProgress(SESSION, false, true);
		} else {
		    publishProgress(SESSION, false, false);
		}
		return null;
	    }
	    publishProgress(SESSION, true);

	    currentServerTime = WSWrapper.getServerTime();

	    final ArrayList<String> ids = WSWrapper.getNewItemsList(previousDownloadTime);

	    if (ids.size() == 0) {
		// Nothing to download
		publishProgress(DONE, 0);
		return null;
	    }

	    publishProgress(LIST, ids.size());
	    for (String id : ids) {
	    	    String data = WSWrapper.readItem(id);
	    	    try {
		        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(data.getBytes("UTF-16")));
		        Item item = parseXmlItem(doc.getElementsByTagName("Root").item(0));
		        publishProgress(ITEM, item);

		    } catch (Exception e) {
		        e.printStackTrace();
		    }
	    }
	    previousDownloadTime = currentServerTime;

	    publishProgress(DONE, ids.size());

	    return null;
	}

	@Override
	protected void onProgressUpdate(Object... values) {
	    switch ((Integer) values[0]) {
	    case SESSION:
		if ((Boolean) values[1]) {
		    tvStatus.setText("User session opened...");
		} else {
		    if ((Boolean) values[2])
			Toast.makeText(
				MyActivity.this,
				"Couldn't open user session, but username and password are right. Please try again.",
				Toast.LENGTH_LONG).show();
		    else
			Toast.makeText(
				MyActivity.this,
				"Couldn't open user session. It seems like your username and password do not match, please try logging in again",
				Toast.LENGTH_LONG).show();
		}
		break;
	    case DONE:
		Integer downloaded = (Integer) values[1];
		if (downloaded == 0)
		    tvStatus.setText("No new items to download - you are already synced!");
		else
		    tvStatus.setText("Successfully downloaded " + downloaded
			    + " items!");
		progress.setVisibility(View.GONE);
		break;
	    case LIST:
		Integer toDownload = (Integer) values[1];
		tvStatus.setText("Found " + toDownload + " items to download.");
		progress.setMax(toDownload);
		progress.setProgress(0);
		break;
	    case ITEM:
		itemList.add((Item) values[1]);
		adapter.notifyDataSetChanged();
		progress.incrementProgressBy(1);
		tvStatus.setText(progress.getProgress() + "/"
			+ progress.getMax() + " downloaded.");
		break;
	    }
	}
    }