i try to parse a large xml document in a AsyncTask. The FeinstaubActivity starts but i only see a black screen and then get back to the RSSReaderActivity from where i starte
Ah, not sure you can do that: http://developer.android.com/reference/android/os/AsyncTask.html shows that execute returns void.
You want this:
Document document = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.feinstaub);
new ParseXMLFile().execute();
}
void setDocument(Document document){ this.document = document; }
private class ParseXMLFile extends AsyncTask<Integer, Integer, Document>{
@Override public void onPostExecute(Document d){ setDocument(d); }
@Override
protected Document doInBackground(Integer... params) {
Document parsedXML = null;
try {
parsedXML = builder.parse(getApplicationContext().getResources().openRawResource(R.raw.finedust));
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parsedXML;
}
}
There's a bit of scoping you need to do: pass the parent activity in or declare the setDocument
method appropriately somehow so you can call it back from inside the AsyncTask, but something like that should do it.