create an async task for online js parsing

This commit is contained in:
Philipp Schaefer
2013-07-09 00:14:12 +02:00
parent c2634ce266
commit 7fcb1e0874
4 changed files with 60 additions and 15 deletions

View File

@ -0,0 +1,31 @@
package com.cradle.iitc_mobile.async;
import android.os.AsyncTask;
import com.cradle.iitc_mobile.IITC_Mobile;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
/*
* this class parses the content of an web page.
* since network operations shouldn't be done on main UI thread
* we use an async task for this.
*/
public class UrlContentToString extends AsyncTask<URL, Integer, String> {
@Override
protected String doInBackground(URL... urls) {
String js = "";
URL url = urls[0];
try {
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A")
.next();
} catch (IOException e) {
e.printStackTrace();
}
return js;
}
}