Issue
in my App i do different requests to get the HTML code of a website. After that, the App parses the HTML, maybe another request will performed and parsed. At the end a ListView is filled with the parsed data.
Now i read that Volley runs all code in the onResponse method on the UI Thread. So maybe it is better to do the parsing in a new thread. I implemented it as follows.
new Thread(new HTMLSiteParsingTask(response)).start();
class HTMLSiteParsingTask implements Runnable {
String mResponse;
HTMLSiteParsingTask(String response) {
mResponse = response;
}
public void run() {
//do something...
callerActivity.addData(dataHashMap);
}
}
At the end of the processing i call a method of the MainActivity to add the data to the Listview "callerActivity.addData(dataHashMap);". This Method does the following:
runOnUiThread(new AddItemsTask(ItemList));
Is there a difference between AsyncTask and Thread so that i should use one of them? Or doesn't matter? Is there maybe a better way to do that stuff?
Thank you for your answers
Solution
Implement a custom request. Place your parsing logic in the parseNetworkResponse
method - it will be called by Volley from a worker thread.
Answered By - artkoenig
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.