0

Asnc Task メソッドを使用して進行状況を更新する必要があるファイル ダウンロード アプリケーションを取得しました。進行状況は、Google Play のサンプルのように、ダイアログと通知バーによって同時に表示されます。

メソッドを実行すると、通知バーの応答が非常に遅くなります。ONProgressUpdate では、同期せずに 2 つの UI 進行状況のみを更新します。

スレッド スリープを使用してプロセスを遅くすると、スムーズに実行されますが、ダウンロード速度が非常に遅くなります。

許容できる高速なダウンロード速度を維持しながら、2 つの UI スレッドがスムーズに実行されるようにするにはどうすればよいでしょうか?

これがコードです

お答えください :)

@Override
protected void onProgressUpdate(Integer... values) {
    if (values.length>0) {
        //Log.d("Download Activity", "progressUpdate:"+values[0]);
        if (values[0] < 0) {
            this.cancel(true);
            showNetworkErrorDialog();
        } else {
            //size += values[0];
            //Log.d("Download Activity", "download size:"+size);
            //downloadedGoodListSize += values[0];
            //downloadProgressBar.incrementProgressBy(values[0]);
            setCurrentProgress(values[0]);
            downloadProgressBar.setProgress(values[0]);
            double currentProg = downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100;
            //progressTextView.setText( decimalFormat.format(downloadedGoodListSize*1.0/downloadProgressBar.getMax()*100.0)+"%");
            progressTextView.setText(decimalFormat.format(downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100)+"%");


            notification.contentView.setProgressBar(R.id.pb, 100, (int)currentProg, false);

            nm.notify(notificationID, notification);

        }
    }
}

@Override
protected void onPostExecute(Boolean result) {
    Log.i("Download Activity", "onPostExecute: starting");
    downloadProgressBar.setProgress(downloadProgressBar.getMax());
    progressTextView.setText(100+"%");
    wheelProgressBar.setVisibility(View.GONE);
    downloadingTextView.setText(getFinishedText());

   notification.contentView.setProgressBar(R.id.pb, 100, 100, false);
   nm.notify(notificationID, notification);
   nm.cancelAll();

    Log.i("Download Activity", "onPostExecute: set interface ok");
    finishDialog.show();

}
4

2 に答える 2

1

非常に頻繁に通知バーを更新しているため、応答が遅くなります。2〜3秒に1回更新すれば問題ありません。

于 2012-07-23T07:46:30.133 に答える
0

以下は私のコードです

@Override
    protected void onProgressUpdate(Integer... values) {
        if (values.length>0) {
            //Log.d("Download Activity", "progressUpdate:"+values[0]);
            if (values[0] < 0) {
                this.cancel(true);
                showNetworkErrorDialog();
            } else {
                //size += values[0];
                //Log.d("Download Activity", "download size:"+size);
                //downloadedGoodListSize += values[0];
                //downloadProgressBar.incrementProgressBy(values[0]);
                setCurrentProgress(values[0]);
                downloadProgressBar.setProgress(values[0]);
                double currentProg = downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100;
                //progressTextView.setText( decimalFormat.format(downloadedGoodListSize*1.0/downloadProgressBar.getMax()*100.0)+"%");
                progressTextView.setText(decimalFormat.format(downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100)+"%");


                notification.contentView.setProgressBar(R.id.pb, 100, (int)currentProg, false);

                nm.notify(notificationID, notification);

            }
        }
    }

@Override
    protected void onPostExecute(Boolean result) {
        Log.i("Download Activity", "onPostExecute: starting");
        downloadProgressBar.setProgress(downloadProgressBar.getMax());
        progressTextView.setText(100+"%");
        wheelProgressBar.setVisibility(View.GONE);
        downloadingTextView.setText(getFinishedText());

       notification.contentView.setProgressBar(R.id.pb, 100, 100, false);
       nm.notify(notificationID, notification);
       nm.cancelAll();

        Log.i("Download Activity", "onPostExecute: set interface ok");
        finishDialog.show();

    }
于 2012-07-23T04:00:40.983 に答える