I'm having a bad time with "ProgressThings". I have an app that dynamically changes the contents of the Views (and even the Views themselves might change, disappear, be re-added, so on). There are some classes that takes care of particular "styles" of the main Activity. One of them downloads a XML file, parses it (there is a specific class to handle this) and show some content to the user based on what was downloaded.
Anyway, my problem is that I wanted the ProgressDialog to be non blocking, so that the user could interact with other app's features while waiting. I have read some answers related to this problem (like this one, for example), but I have not been successful so far. Changing to ProgressBar with the "setIndeterminate(true)" (for I want the spinning style) doesn't seen to be working (it simply doesn't appear).
The private class bellow is the one that I use to show the ProgressDialog. It is working the way I posted bellow, but it is blocking UI interactions =/.
private class DownloadXmlTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog mProgress;
private int xmlType = 0;
XmlHandler xmlHandler = null;
DownloadXmlTask(){
xmlHandler = new XmlHandler();
}
@Override
protected void onPreExecute(){
mProgress = new ProgressDialog(context);
mProgress.getWindow().setGravity(Gravity.CENTER);
mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgress.setIndeterminate(true);
mProgress.setMessage("Carregando...");
mProgress.show();
}
@Override
protected Boolean doInBackground(String... urls) {
int count = urls.length;
for(int i=0; i<count; i++){
parseXml(urls[i]);
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if(result == true){
mProgress.dismiss();
// Do something else
}
}
/**
* Parses the xml defined by the parameter's String
* @param urlString The url's String
*/
private void parseXml(String urlString){
try {
// Loads the url
URL url = new URL(urlString);
// Initializes the parser
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
// Sets the handler
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(xmlHandler);
// Parses
xr.parse(new InputSource(url.openStream()));
}catch(Exception e) {
// To something here
}
}
}
P.S.: I didn't put the code for the XmlHandler class for it is not necessary ;P
P.S.2: Thanks in advance for any help :D