避免多次刷新 Notification

This commit is contained in:
seven332 committed 2014-12-27 13:54:46 +08:00
1 parent 690874b6a9
commit 3ed95dbdfc
1 file changed
+8 -1
@@ -364,6 +364,8 @@ public class DownloadService extends Service
notifyUpdate();
}
private long mLastStartForegroundTime = 0;
@Override
public void onDownload(int gid, int downloadSize, int totalSize) {
if (mCurDownloadInfo == null)
@@ -377,7 +379,12 @@ public class DownloadService extends Service
mBuilder.setContentTitle(getString(R.string.downloading) + " " + gid)
.setContentText(mSpeedStr)
.setProgress(totalSize, downloadSize, false);
startForeground(DOWNLOADING_NOTIFY_ID, mBuilder.build());
long now = System.currentTimeMillis();
if (now - mLastStartForegroundTime > 500) {
startForeground(DOWNLOADING_NOTIFY_ID, mBuilder.build());
mLastStartForegroundTime = now;
}
notifyUpdate();
}