http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/

On Sunday, December 23, 2012 1:27:54 PM UTC+2, Antonis Kanaris wrote:
>
> Hello.I make an intent service for download data and store to a string.How 
> i pass the data (string s inside my code) to main activity?
>
>   i try this code...
>
>   
>
> public class DownloadService extends IntentService {
> private int result = Activity.RESULT_CANCELED;public String s = "";
> public DownloadService() {super("DownloadService");}
> // Will be called asynchronously be Android@Overrideprotected 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;
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to