I need to parse an xml file which takes about 3 seconds, and immediately use the data that is parsed from the xml file after it has completed. However, since it takes around 3 seconds to complete, i don't just want the screen sitting and waiting for 3 seconds showing nothing. I would like it to display a ProgressDialog. I've tried everything in these threads and while most do 2 / 3, none seem to do all 3.
Basically I have a button that when pressed, i want to parse the xml file and then use the data parsed from the file:
void onButtonClicked() {
ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("Parsing...");
pd.show();
String[] ret;
return = parseXmlFile();
pd.dismiss();
if (ret[0] == "steve") {
sayHiToSteve();
}
}
If I use an asyncTask, it will continue on with execution and check ret[0] before the task is completed and will just be null. if i do AsyncTask.get(), it pauses the execution but doesn't display the progress dialog, so that's no good either.
I also looked at creating a seperate thread, but i had the same problem. I can't use a timer, because it is about 3 seconds (but can be up to 4 or 5 seconds if connection is slow), so i can't approximate.
Any help is much appreciated. Thanks in advance.