Android通知进度条冻结

这是我正在使用的代码

http://pastebin.com/3bMCKURu

问题是,经过一段时间后(文件变得越来越重)通知栏下拉速度越来越慢,最后它就冻结了!

我遇到了类似的问题,看起来RemoteViews有内存泄漏,不应该重复使用。

看看这些主题:

通知服务中的android内存泄漏

http://code.google.com/p/android/issues/detail?id=13941

http://groups.google.com/group/android-developers/browse_thread/thread/667343a171e51463#

祝好运

这是一种常见的行为。 您不应该频繁更新泛洪NotificationManager。 您应该决定更新的时间间隔,例如每秒两次。

例如,

long startTime; long elapsedTime = 0L; if (elapsedTime > 500) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { mBuilder.setProgress(100, (int) newValue, false); mNotifyManager.notify(notificationID, mBuilder.build()); startTime = System.currentTimeMillis(); elapsedTime = 0; } }); Log.d("Andrognito", newValue + "Progress"); } else elapsedTime = new Date().getTime() - startTime; 

这对我来说非常有效,也不会冻结通知。 希望这可以帮助!

您的通知太频繁了。 这就是冻结的原因。 让它们以更大的间隔更新。 好的是每秒或2秒一次。

这个解决方案对我有用(丑陋但有效):

 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; } ... }