updating the notification status bar and progress bar as well while downloading file in android
<p>When i am downloading the file my progress bar is get stuck but my status bar in notification part was still running. When downloading is started initially it works but after completion of some part of downloading it takes more time to update in the progress bar where status bar i   .Please help me out...
Thank in advance.</p>

<hr>

<pre><code>public class FileDownloadTestActivity extends Activity {

private static String url = "http://www.xxxx.in/build/android/android/xxxx.apk";
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
private Button startBtn;
private ProgressDialog mProgressDialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    startBtn = (Button) findViewById(R.id.download);
    startBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            new DownloadFileAsync().execute(url);
        }
    });
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_DOWNLOAD_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage("Downloading file..");
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();
        return mProgressDialog;
    default:
        return null;
    }

}

class DownloadFileAsync extends AsyncTask&lt;String, String, String&gt; {

    ProgressBar progressBar;
    private int progress = 1;
    NotificationManager notificationManager;
    Notification notification2;
    int downloadedSize;
    int totalSize;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
         Intent intent = new Intent();
            final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

            notification2 = new Notification(R.drawable.ic_launcher, "DOWNLOADING: " , System
                    .currentTimeMillis());
            notification2.flags = notification2.flags | Notification.FLAG_ONGOING_EVENT;
            notification2.flags = notification2.flags|Notification.FLAG_AUTO_CANCEL;
           // notification2.flags = notification2.flags|Notification.FLAG_NO_CLEAR;
            notification2.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.custom_notification_layout);
            notification2.contentIntent = pendingIntent;
            notification2.contentView.setImageViewResource(R.id.status_icon,R.drawable.junow );

            notification2.contentView.setProgressBar(R.id.status_progress, 100, progress, false);

            getApplicationContext();
            notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

            notificationManager.notify(1, notification2);

        showDialog(DIALOG_DOWNLOAD_PROGRESS);

    }

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

        try {

            URL url = new URL(aurl[0]);
            URLConnection conexion = url.openConnection();
            conexion.connect();

            int lenghtOfFile = conexion.getContentLength();

            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory()+"/Juno.apk");

            byte data[] = new byte[1024];
            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                long var=(int) ((total * 100) / lenghtOfFile);

                output.write(data, 0, count);
                publishProgress("" + var);
            }

            output.flush();
            output.close();
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    protected void onProgressUpdate(String... progress) {
        System.out.println("progress--------    1    "+progress[0]);

         notification2.contentView.setProgressBar(R.id.status_progress, 100,Integer.parseInt(progress[0]), false);
         notification2.contentView.setTextViewText(R.id.percent,"Downloading in progress  "+progress[0]+" %");
         notificationManager.notify(1, notification2);
         //notificationManager.notifyAll();
         mProgressDialog.setProgress(Integer.parseInt(progress[0]));
         System.out.println("progress-------  2       "+progress[0]);

    }

    @Override
    protected void onPostExecute(String unused) {
        dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        notificationManager.cancel(42); 

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Juno.apk")), "application/vnd.android.package-archive");
        startActivity(intent); 


    }

}
</code></pre>
