0

アプリケーションのロード中にフリーズします。通知なしでファイルをダウンロードすると、正しく実行されます。何が問題なのですか?

        protected void onProgressUpdate(final Integer... values) {
                       new Thread(new Runnable() {
                            public void run() {

                                    mHandler.post(new Runnable() {
                                        public void run() {
                                             int progress=(int) ((values[0] / (float) values[1]) * 100);
                                                Integer textProgress=new Integer(progress);
                                               notification.contentView.setProgressBar(R.id.progressBar1, 100, progress, false);
                                               notification.contentView.setTextViewText(R.id.progress, textProgress.toString()+"%");
                                               myNotificationManager.notify(NOTIFY_ID, notification);
                                        }
                                    });
                                }
                            }).start();

                  }

この行のlogcat

  08-13 05:52:34.039: E/ActivityManager(59): ANR in com.example.webbrawsermanat (com.example.webbrawsermanat/.WebBrawser)
    08-13 05:52:34.039: E/ActivityManager(59): Reason: keyDispatchingTimedOut
    08-13 05:52:34.039: E/ActivityManager(59): Load: 2.06 / 0.9 / 0.35
    08-13 05:52:34.039: E/ActivityManager(59): CPU usage from 23968ms to 36ms ago:
    08-13 05:52:34.039: E/ActivityManager(59):   system_server: 79% = 77% user + 1% kernel / faults: 2446 minor 12 major
    08-13 05:52:34.039: E/ActivityManager(59):   webbrawsermanat: 19% = 19% user + 0% kernel / faults: 271 minor 3 major
    08-13 05:52:34.039: E/ActivityManager(59):   m.android.phone: 0% = 0% user + 0% kernel / faults: 247 minor
    08-13 05:52:34.039: E/ActivityManager(59):   ndroid.launcher: 0% = 0% user + 0% kernel / faults: 133 minor
    08-13 05:52:34.039: E/ActivityManager(59):   kswapd0: 0% = 0% user + 0% kernel
    08-13 05:52:34.039: E/ActivityManager(59):   mmcqd: 0% = 0% user + 0% kernel
    08-13 05:52:34.039: E/ActivityManager(59):   qemud: 0% = 0% user + 0% kernel / faults: 3 minor
    08-13 05:52:34.039: E/ActivityManager(59):   adbd: 0% = 0% user + 0% kernel
    08-13 05:52:34.039: E/ActivityManager(59):   ronsoft.openwnn: 0% = 0% user + 0% kernel / faults: 157 minor
    08-13 05:52:34.039: E/ActivityManager(59):   ndroid.settings: 0% = 0% user + 0% kernel / faults: 156 minor
    08-13 05:52:34.039: E/ActivityManager(59):   zygote: 0% = 0% user + 0% kernel / faults: 179 minor
    08-13 05:52:34.039: E/ActivityManager(59):   d.process.media: 0% = 0% user + 0% kernel / faults: 129 minor
    08-13 05:52:34.039: E/ActivityManager(59):   com.android.mms: 0% = 0% user + 0% kernel / faults: 130 minor 1 major
    08-13 05:52:34.039: E/ActivityManager(59): TOTAL: 99% = 97% user + 1% kernel + 0% iowait
4

1 に答える 1

0

実際には、スレッドとランナブルのすべてのネストは必要ありません。これがサブクラスにあると仮定して、これをAsyncTask使用します。

protected void onProgressUpdate(final Integer... values) {
   int progress=(int) ((values[0] / (float) values[1]) * 100);
   Integer textProgress=new Integer(progress);
   notification.contentView.setProgressBar(R.id.progressBar1, 100, progress, false);
   notification.contentView.setTextViewText(R.id.progress, textProgress.toString()+"%");
   myNotificationManager.notify(NOTIFY_ID, notification);
}

onProgressUpdate()メイン(UI)スレッドで呼び出されるため、UI操作を直接実行しても安全です。

于 2012-08-12T09:47:16.793 に答える