I'm trying to start the chronometer in a new notification but from a paused(elapsed) "the elapsed time is got from another chronometer", not from zero
The start base in Notification RemoteViews.class of chronometer is different from the start base in Chronometer.class it has different calculations
Notification notification = new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(songName).build();
notification.contentView = simpleContentView;
And I get the timeWhenPaused
long timeWhenPaused = myChronometer.getBase() - SystemClock.elapsedRealtime();
Then create the chronometer
notification.contentView.setChronometer(R.id.chronometer_recorder
, (SystemClock.elapsedRealtime() + timeWhenPaused)
, null
, true
);
It starts from Zero
I hope this will help >>>> my working example of a chronometer using remote views (in the notification).
long startTime = SystemClock.elapsedRealtime();
Calendar endTime = Calendar.getInstance(); // time in future
endTime.set(Calendar.HOUR_OF_DAY, YOUR_HOUR);
endTime.set(Calendar.MINUTE, YOUR_MINUTE);
endTime.set(Calendar.SECOND, 0);
Date now = new Date();
long elapsed = now.getTime() - endTime.getTimeInMillis();
long remainingTime = startTime - elapsed;
remoteViews.setChronometerCountDown(R.id.chronometer, true);
remoteViews.setChronometer(R.id.chronometer, remainingTime, ("%tH:%tM:%tS"), true);
picture of my notification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With