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 6828381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:34+00:00 2026-05-26T22:22:34+00:00

in my app i have 4 buttons and when the user clicks any of

  • 0

in my app i have 4 buttons and when the user clicks any of the button it starts downloading a file and the progress bar gets shown in the notification area. The downloading and progress bar is working fine, but i have the following two problems

  1. When the download completes the progress bar is not getting closed, it remains in the notification area
  2. As i said above i have 4 buttons and when the first button is clicked download gets started and when the other three buttons are clicked immediately download is not taking place. I thought it may start after first download completes. But nothing happens. How to show all the progress bar when all buttons clicked

Following is my code(here i have added only 2 buttons) pls help me

b1 = (Button)findViewById(R.id.button1);
        b1.setOnClickListener(new View.OnClickListener() 
        {   
            @Override
            public void onClick(View v) 
            {
                i =1;
                Intent intent = new Intent(NotificationProgressTestActivity.this, UploadService.class);
                startService(intent);
            }
        });

        b2 = (Button)findViewById(R.id.button2);
        b2.setOnClickListener(new View.OnClickListener() 
        {   
            @Override
            public void onClick(View v) 
            {
                i = 2;
                Intent intent = new Intent(NotificationProgressTestActivity.this, UploadService.class);
                startService(intent);
            }
        });

Next following is my Uplaod Service.class

public class UploadService extends IntentService
{   
    private NotificationManager notificationManager;
    private Notification notification;
    private int progress = 10;
    private static String fileName = "folder/";
    private static URL url;
    public UploadService(String name) 
    {
        super(name);
    }
    public UploadService()
    {
        super("UploadService");
    }
    @Override
    protected void onHandleIntent(Intent intent) 
    {
        notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
        notification = new Notification(R.drawable.icon,"Uploading file", System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
        notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.upload_progress_bar);
        notification.contentIntent = contentIntent;
        notification.contentView.setProgressBar(R.id.progressBar1, 100, progress, false);
        notificationManager.notify(42, notification);
        notificationManager.notify(42, notification);
        Thread download = new Thread() 
        {
            @Override
            public void run() 
            {
                Log.e("download", "start");
                try
                {
                    for (int i = 1; i < 100; i++) 
                    {    
                        progress++;
                        notification.contentView.setProgressBar(R.id.progressBar1, 100, progress, false);
                        if(i==1)
                        {  
                            if(NotificationProgressTestActivity.i ==1 )
                            {
                                url = new URL("http://xxxxxxxxxxxxxxxx.mp4");
                            }
                            else if(NotificationProgressTestActivity.i == 2)
                            {
                                url = new URL("http://xxxxxxxxxxxxxxxx.mp4");
                            }
                            HttpURLConnection c = (HttpURLConnection) url.openConnection();
                            c.setRequestMethod("GET");
                            c.setDoOutput(true);
                            c.connect();

                            String PATH = Environment.getExternalStorageDirectory()+ "/";
                            Log.e("PATH:", PATH);
                            File file = new File(PATH);
                            if (!file.exists()) 
                            {
                                file.mkdir();
                                Log.e("destination", "created");
                            } 
                            else 
                            {
                                Log.e("destination", "exist");
                            }
                            File outputFile = new File(file, fileName);
                            FileOutputStream fos = new FileOutputStream(outputFile);

                            InputStream is = c.getInputStream();

                            byte[] buffer = new byte[10171188];
                            int len1 = 0;
                            while ((len1 = is.read(buffer)) != -1) 
                            {
                                fos.write(buffer, 0, len1);
                            }
                            fos.close();
                            is.close();
                            //  -----------------------
                            if (!outputFile.exists()) 
                            {
                                Log.e(outputFile.toString(), "not created");
                            }
                            else 
                            {
                                Log.e(outputFile.toString(), "created");
                                Log.e(outputFile.toString(), "" + outputFile.length());
                            }
                            Log.e("download", "end");
                        }
                        notificationManager.notify(42, notification);
                        try 
                        {
                            Thread.sleep(1017);
                        }
                        catch (InterruptedException e) 
                        {
                            e.printStackTrace();
                        }
                 }
            }
            catch (IOException e) 
            {
                        Log.e("log_tag", "Error: " + e);
            }
            Log.e("log_tag", "Check: ");

                // remove the notification (we're done)
            notificationManager.cancel(42);
        }
     };
        download.run();
    }
  • 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-26T22:22:35+00:00Added an answer on May 26, 2026 at 10:22 pm
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    

    1- in this above line, the 2nd parameter in getActivity() is requestCode, it should be a unique number for each button. currently it is 0 for both buttons.

    notificationManager.notify(42, notification);
    

    2- in the above line, the notification index you are passing as 42, it should be unique for both buttons. currently no matter how many buttons you create it will never show you a new notification because you are passing 42 for each. it will keep updating the current one.

    also you might need to look again the code you are doing in onHandleIntent(). there are better ways to do this.

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

Sidebar

Related Questions

In my flex app I have some radio buttons. When a user clicks the
i have just created a drum app. The user taps on the individual buttons
I have an app where the user presses a button and a custom spinner
my app have action bar on top of windows. Where are some buttons. Buttons
I have silverlight application. What I want is. If my user clicks on Button
I have a checkin related app. When user clicks a venue on map, callout
In my application, I have recording button. I want when user clicks on it
I have two buttons in my flex app next to each other, ButtonA and
I have several buttons on my app that are being created dynamically. They are
So I have these buttons in my app that I want to open .PDF

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.