I have a notification build with chronometer enabled. I also have notification actions which pauses and resumes my task along with the chronometer obviously. But I cannot make the chronometer pickup from the earlier elapsed time. My time calculation is as below.
private void pauseTask(){
updateNotification(createNotification(action).setUsesChronometer(false).build(), Config.NOTIFICATION_ID);
elapsedTime = System.currentTimeMillis() + (System.currentTimeMillis() - startTime);
//perform pause operation here
}
private void resumeTask(){
startTime = System.currentTimeMillis();
long time = System.currentTimeMillis() - (startTime - elapsedTime);
updateNotification(createNotification(action)
.setWhen(time)
.build(), Config.NOTIFICATION_ID);
//Perform pause task
}
The startTime
in pauseTask
is time obtained when the action was started fresh