I have a service that updates a notification every millisecond (stopwatch).
It works fine initially, the problem is, the app eventually slows down and stopwatch updates look really laggy. I've pinpointed this issue to the fact that I'm resetting the notification's contentview. If i comment out that code, the timer runs fine indefinitely. If I leave that line in, the timer and app slow down significantly after about 1-2 minutes.
code to create notification:
notificationContent.setImageViewResource(R.id.image, R.drawable.ic_main);
notificationContent.setTextViewText(R.id.exerciseName, _currentExercise.getTitle());
notificationContent.setTextViewText(R.id.setNumber, "Set " + _currentSet + "/" + _currentExercise.getSets());
notificationContent.setTextViewText(R.id.timeElapsed, getFormattedElapsedTime());
notificationContent.setOnClickPendingIntent(R.id.notifButton, setComplete);
mBuilder.setSmallIcon(icon); //for some reason I need this for my view to show up
mBuilder.setContentIntent(contentIntent);
notification = mBuilder.build();
notification.bigContentView = notificationContent;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
//attach notification and ensure service continues to run in foreground after activity is destroyed
startForeground(NOTIFICATION_ID, notification);
code to update notification (called every millisecond):
notificationContent.setTextViewText(R.id.exerciseName, _currentExercise.getTitle());
notificationContent.setTextViewText(R.id.setNumber, getString(R.string.sets_prefix, _currentSet, _currentExercise.getSets()));
notificationContent.setTextViewText(R.id.timeElapsed, getFormattedElapsedTime());
notification = mBuilder.build();
notification.bigContentView = notificationContent;
mNotificationManager.notify(NOTIFICATION_ID,notification);
That one line: notification.bigContentView = notificationContent;
creates the slow down. If I remove that, the app runs smoothly indefinitely. If I leave it in, my app slows down. And it gets slower overtime too. Like it starts to slow down after a minute, and by 5 minutes, its unbearably slow and laggy. I don't know why updating the notification's view would cause this. Any help would be greatly appreciated.