I’m using an asynctask to run a client protocol. The asynctask works fine, however it takes a (very noticable) few seconds to start running.
I’ve done some debugging and the button that calls the execute remains highlighted for several seconds, then onPreExecute() fires, and the process bar that I have running starts.
So my question is simply: is Asynctask always this slow to start or is there a chance of some sort of problem here?
Here’s the button (and the onClickListener) in question. This code is found in onCreate(Bundle SavedInstanceState):
mSave = (Button)findViewById(R.id.btnSave);
mSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(),
"marker", Toast.LENGTH_LONG).show();
if (portrait != null && !mComments.getText().toString().equals("")) {
for (int i = 0; i < 6; i++) {
checked[i] = checkBoxes[i].isChecked();
checkBoxFields[i] = checkBoxes[i].getText().toString();
}
new ClientProtocol().execute();
}
}
});
Here’s onPreExecute(), although I’m pretty sure the pause is somewhere before this:
@Override
protected void onPreExecute() {
mProgress = 0;
mLoad.setVisibility(View.VISIBLE);
mSave.setClickable(false);
mFinal = "";
mClientThoughts = mComments.getText().toString();
mCheckBoxes = checkBoxFields;
mChecked = checked;
mBaos = new ByteArrayOutputStream();
portrait.compress(Bitmap.CompressFormat.PNG, 100, mBaos);
mClientImage = mBaos.toByteArray();
}
From your description seems like the delay is even before your onPreExecute() fires? Is there perhaps something delaying your button processing (maybe handler?) causing this?