I have created an intent download service and I want to pass download data to Toast and into Text in main activity. Download service should start from alarm manager repeatedly. How do I do this?
Currently, it does not show in Toast, but I have network traffic; data is downloaded but not shown.
Relevant code:
public class DownloadService extends IntentService {
public String response;
public DownloadService() {
super("DownloadService");
}
// Will be called asynchronously be Android
@Override
protected void onHandleIntent(Intent intent) {
//String urldown = intent.getStringExtra("url");
String urldown="http://......";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urldown);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (IOException e) {
e.printStackTrace();
}
Intent intentsend=new Intent("update");
intentsend.putExtra( "downdata",response);
sendBroadcast(intentsend);
}