I want an example read data from web and out to textview with intent service.I read this http://www.vogella.com/articles/AndroidServices/article.html but download the file...i want store data to string for use in another function in main activity.Thanks.
public class DownloadService extends IntentService {
private int result = Activity.RESULT_CANCELED;
public String s = "";
public DownloadService() {
super("DownloadService");
}
// Will be called asynchronously be Android
@Override
protected void onHandleIntent(Intent intent) {
Uri data = intent.getData();
String urlPath = intent.getStringExtra("urlpath");
InputStream stream = null;
//FileOutputStream fos = null;
try {
URL url = new URL(urlPath);
stream = url.openConnection().getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
//fos = new FileOutputStream(output.getPath());
int next = -1;
while ((next = reader.read()) != -1) {
//fos.write(next);
s=s+next;
}
// Sucessful finished
result = Activity.RESULT_OK;