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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:22:25+00:00 2026-05-29T06:22:25+00:00

Hi I’m currently developing an app that requires a very large download (100-200MB) on

  • 0

Hi I’m currently developing an app that requires a very large download (100-200MB) on the first launch of the application.

My first activity starts a service, which has an asynctask to do all the downloading.

To show the progress of my download I’m doing the following:

First using AsyncTask’s publishProgress/onProgressUpdate I send a broadcast to my activity with the current progress:

@Override
protected Void doInBackground(Void... params) { 
  ...
  publishProgress(Integer.toString(completedFiles), current_filename, Integer.toString(file_progress));
  ...
}
@Override
protected void onProgressUpdate(String... progress) {
        super.onProgressUpdate(progress);
        progressBroadcast.putExtra(NOTIFY_DOWNLOAD_PROGRESS, progress);
        sendOrderedBroadcast(progressBroadcast, null);
}

The on my activty I have a BroadcastReceiver that updates the progressbar

    private class ProgressReceiver extends BroadcastReceiver{

    private int totalFiles;

    public ProgressReceiver(Context context) {
        progressDialog = new ProgressDialog(context);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(ResourceDownloadService.NOTIFY_DOWNLOAD_START.equals(action)){               
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setCancelable(false);
            progressDialog.setTitle(getString(R.string.loading_res_dialog_title));
            totalFiles = intent.getIntExtra(ResourceDownloadService.TOTAL_FILES, 0);
            progressDialog.setMessage("Downloading Resources");
            progressDialog.show();
        }else if(ResourceDownloadService.NOTIFY_DOWNLOAD_END.equals(action)){
            //Hide progress bar one we are done
            progressDialog.dismiss();
            startIntroActivity();
        }else{
            String[] progress_info = intent.getExtras().getStringArray(ResourceDownloadService.NOTIFY_DOWNLOAD_PROGRESS);
            int completedFiles = Integer.parseInt(progress_info[0]);
            String filename = progress_info[1];
            int progress = Integer.parseInt(progress_info[2]);
            progressDialog.setProgress(progress);
            progressDialog.setMessage("Downloading "+filename +"\n"+completedFiles +" files downloaded of "+totalFiles);
        }
    }

}

So I’m not sure of what I’m doing wrong here, because after a couple of seconds that the progress bar is showing I get an ANR.

Could it be because I’m sending too much broadcasts to update the progress bar??

  • 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-29T06:22:25+00:00Added an answer on May 29, 2026 at 6:22 am

    The only thing I can think of is the ANR is due to the progress dialog disabling interaction for so long, try removing the dialog and using a different method to notify the user of progress.

    Something like this

    public interface Listener {
    
        public abstract void onEvent();
    
    }
    

    in the broadcast receiver create a static reference and setter

    private static MessageListener mListener = null;

    @Override
    public void onReceive(Context context, Intent intent) {
        //stuff
        if(mListener != null)
             mListener.onEvent();   
    }
    
    public static void setListener(Listener l) {
        mListener = l;
    }
    

    then implement the listener in the Activity

    class MyActivity implements Listener{
    
    @Override
    public void onResume(){
        //register the listener so that when the activity is visible it can receive updates
        BroadCastReceiver.setListener(this);
    }
    
    @Override
    public void onPause(){
        //unregister the listener so the activity doesn't receive updates while in the background
        BroadCastReceiver.setListener(null);
    }
    @Override
    public void onEvent(){
        //update the UI
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

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.