title: Download multiple files using a Service in android
body: <p>My application has a lot of optional data that can be downloaded so I decided to use a Service to handle all the downloads in the background, So I started learning it and here is where i got:</p>
  
  <pre><code>public class DownloadService extends IntentService{
  
      public DownloadService() {
          super("DownloadService");
  
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
  
          String URL=intent.getStringExtra("DownloadService_URL");
          String FileName=intent.getStringExtra("DownloadService_FILENAME");
          String Path=intent.getStringExtra("DownloadService_PATH");
  
          try{
          URL url = new URL(URL);
          URLConnection conexion = url.openConnection();
  
          conexion.connect();
  
  
          InputStream input = new BufferedInputStream(url.openStream());
          OutputStream output = new FileOutputStream(Path+FileName);
  
          byte data[] = new byte[1024];
  
          int count = 0;
          while ((count = input.read(data)) != -1) {
              output.write(data);
          }
  
          output.flush();
          output.close();
          input.close();
  
          }
          catch(Exception e){ }
      }
  
  }
  </code></pre>
  
  <p>The code from the main activity:</p>
  
  <pre><code>        Intent ServiceIntent = new Intent(this,DownloadService.class);
          ServiceIntent.putExtra("DownloadService_URL", "the url...");
          ServiceIntent.putExtra("DownloadService_FILENAME", "Test1.rar");
          ServiceIntent.putExtra("DownloadService_PATH", "/sdcard/test/");
          startService(ServiceIntent);
  </code></pre>
  
  <ol>
  <li>Is the code used to download the files correct? Am I using the Service correctly?  </li>
  <li>I want to download a lot of files.. So should I startService for each different URL?  </li>
  <li>I would like to inform the user of the percentage done.. But the Service doesnt have a UI. Should I do that in the notification bar?</li>
  </ol>
  
  <p>Thanks.</p>