Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6383237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:37:27+00:00 2026-05-25T02:37:27+00:00

My application has a lot of optional data that can be downloaded so I

  • 0

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:

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){ }
    }

}

The code from the main activity:

        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);
  1. Is the code used to download the files correct? Am I using the Service correctly?
  2. I want to download a lot of files.. So should I startService for each different URL?
  3. 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?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:37:28+00:00Added an answer on May 25, 2026 at 2:37 am

    Is the code used to download the files correct?

    I don’t like the use of concatenation to create fully-qualified file paths (use the appropriate File constructor). Catching exceptions and not doing anything with them is a really bad idea. On Android 2.3 and higher, you should consider using DownloadManager.

    Otherwise, it’s probably OK for basic stuff.

    I want to download a lot of files.. So should I startService for each different URL?

    That should work fine. Note that they will be downloaded one at a time, as IntentService has only one background thread.

    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?

    That would be one solution. A variation on that would be to have the service send an ordered broadcast, to be picked up by your activity if it is still on-screen or by a BroadcastReceiver that would do the Notification. Here is a blog post with more on that, and here is a tiny sample application demonstrating the concept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an RMI application that has service implementation and it has a lot
My web application has got a lot of service tables/entities, such as payment_methods ,
I'm working on a web application that has a lot to download (javascript, images,
I have an application which has a lot of functions which go through all
I have a class that extends Application which has a lot of methods like:
I have created a JavaScript application that has a lot of array manipulations (sorting,
I am working on a java application which has a lot of use cases.
I have a J2EE application that has a lot of reports, the situation now
Hello: I am developing an application that has a lot of support dll's. some
I'm running a Silverlight 4 application that has a WCF service reference to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.