Updating Progressbar in Notification bar using AsyncTask in a Service?
<p>I'm trying to download multiple binary files using a Service which contains an AsynTask for doing background work. I'm able to run the Service successfully, I've registered it in the Manifest file. I'm able to download the files, however I would like to show a progress bar in the notification bar. I am creating the Notification bar inside the onPreExecute() method and setting the progressbar and notifying the NotifactionManager inside the onProgressUpdate() method.</p>

<pre><code>  private class DownloadFileAsync extends AsyncTask&lt;String, String, String&gt; {


           @Override
           protected void onPreExecute() {
               super.onPreExecute();
               notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
               notification = new Notification(R.drawable.icon, "Downloading...", System.currentTimeMillis());
               contentView = new RemoteViews(getPackageName(), R.layout.progress_layout);
               contentView.setProgressBar(R.id.status_progress, 10, 0, false);        
               contentView.setTextViewText(R.id.status_text,currentFile);       
               notification.contentView = contentView;

              // Toast.makeText(DownloadService.this, "Downloading...!",Toast.LENGTH_SHORT).show();
           }

           @Override
           protected String doInBackground(String... aurl) {
               int count;

               try {
                  //Downloading code goes here
               } catch (Exception e) {}
               return null;

           }
           protected void onProgressUpdate(String... progress) {
                Log.d("ANDRO_ASYNC",progress[0]);

                notification.contentView.setProgressBar(R.id.status_progress, 100, Integer.parseInt(progress[0]), false);
                // inform the progress bar of updates in progress
                notificationManager.notify(NOTIFICATION_ID, notification);



           }

           @Override
           protected void onPostExecute(String unused) {

               Toast.makeText(DownloadService.this, "Download complete!",Toast.LENGTH_SHORT).show();
           }
       }
</code></pre>

<p>The DownloadFileAsync private class is inside the DownloadService class which extends Service. I'm unable to show or update the notification bar. </p>

<p>I'm currently getting an IllegalArgumentException on the line:
                notificationManager.notify(NOTIFICATION_ID, notification);</p>

<p>Would really appreciate your help on this one!</p>

<p>EDIT: NOTIFICATION_ID is defined as follows: private int NOTIFICATION_ID = R.string.app_name</p>
