4

This is the code I'm using

http://pastebin.com/3bMCKURu

The problem is that after some time (File gets more weight) notification bar get slower to pulldown, and finally it just freezes!

Bo Persson
  • 90,663
  • 31
  • 146
  • 203

2 Answers2

3

This solution worked for me (ugly but working):

private static int mPercentDownloaded;

@Override
protected Void doInBackground(String... params) {
...
        mPercentDownloaded = (int) ((total * 100) / lenghtOfFile);
        long currentDownloadTicks = System.currentTimeMillis();
        if (currentDownloadTicks > mDownloadTicks + 1000) {
                publishProgress(mPercentDownloaded);
                mDownloadTicks = currentDownloadTicks;
        }
...
}
LM.Croisez
  • 484
  • 4
  • 10
3

Your notifications are too frequent. thats why it freezes. make them update in bigger intervals. Ok is once in every second or 2 seconds.

DArkO
  • 15,880
  • 12
  • 60
  • 88
  • romhandler.sendMessage(new Message());, it's being called each 1.5 seconds, and after that, handler adds extra 150ms, total 1.65 seconds, so its a long time, or there it's error? sleep it's bad placed? – Jesus David Gulfo Agudelo Jun 17 '11 at 18:33
  • try to use log to see how often your handler is called. the only thing that can freeze your app is running extensive processing tasks in the UI thread and that is the handler in your case. – DArkO Jun 17 '11 at 19:12
  • increased time to 3 seconds, now it go 37% and still dont freezes, i need to wait and see if it freezes – Jesus David Gulfo Agudelo Jun 17 '11 at 19:30
  • as i said add some logs in the handler and see in logcat if your handler gets called more often than you have set it to. – DArkO Jun 18 '11 at 06:34
  • I use System.currentTimeMillis() inside my doInBackground() method of my AsyncTask to slow down the notification sending rythm. This is quite ugly, but it works very well and avoids to flood the system with too much notify events. See my solution below. – LM.Croisez Sep 10 '15 at 14:48