Note that there are some explanatory texts on larger screens.

plurals
  1. POLong running ProgressDialog shows Application not responding (ANR) dialog
    primarykey
    data
    text
    <p>Hi I'm currently developing an app that requires a very large download (100-200MB) on the first launch of the application.</p> <p>My first activity starts a service, which has an asynctask to do all the downloading.</p> <p>To show the progress of my download I'm doing the following:</p> <p>First using AsyncTask's publishProgress/onProgressUpdate I send a broadcast to my activity with the current progress:</p> <pre><code>@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); } </code></pre> <p>The on my activty I have a BroadcastReceiver that updates the progressbar</p> <pre><code> 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); } } } </code></pre> <p>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.</p> <p>Could it be because I'm sending too much broadcasts to update the progress bar??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload