vendredi 17 octobre 2014

using AsyncTask for multiple actions


Vote count:

0




I am working in android.


I have a ParseURL class in my MainActivity.java that extends AsyncTask:


the class parses a URL and then does some work with it.



private class ParseURL extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... strings) {
StringBuffer buffer = new StringBuffer();
Document doc;
try {
Log.i("output", "trying to connect..");
doc = Jsoup.connect("http://sirim.co.il/").get();
Log.i("output", "connected");
Elements metaElems = doc.select("a[class=mainlevelmatkonim]");
for (Element metaElem : metaElems) {
String c = metaElem.text();
buffer.append(c + "\r\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return buffer.toString();
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
httpInfo.setText(s);
}
}


my question is - if I want to use again a AsyncTask to parse another page - but do different actions with the parsed page -


should I use the same class or create a new one?


what is the right way? have a "if" statement or something like that to check what to do with the parsed page? or have a few AsyncTask classes that do different work?


thnaks in advance, Ofek



asked 1 min ago







using AsyncTask for multiple actions

Aucun commentaire:

Enregistrer un commentaire