Handling the Background Processing

Now you need to identify what processing should run asynchronously. Again, this is the downloading and parsing code. The following code (with exception handling removed for clarity) shows how to override the doInBackground() method: @Override protected Boolean doInBackground(String... params) { boolean result = false; startingNumber = (Integer)params[1]; String pathToQuestions = params[0] +

"?max=" + QUESTION_BATCH_SIZE + "&start=" + startingNumber; result = loadQuestionBatch(startingNumber, pathToQuestions); return result;

Here, the background processing simply involves determining the appropriate question batch to download and calling the helper method loadQuestionBatch(). This method must be moved into the QuizTask class and updated to contact the application server. Again, this is simply a matter of generating the appropriate URL, opening the stream to the remote application server, and using the setInput() method of XmlPullParser.

For the full code to the implementation, please see the sample code provided on this book's website.

ByWay

0 0

Post a comment