I am trying to execute a time counter (counts from 0) that basically gets the saved time variable (startTime that was created as soon as the user clicked the button) and subtracts the current time (Calendar.getInstance () maybe?), So the result will be the difference (in HH: MM: SS) between two points. This method will run on every tick of the chronometer, so the text view will be updated every second, effectively creating my timer.
Now I take this circular route, because this is the only way I could count in order to save the elapsed time, even if the application is killed. This is because the startTime variable is stored in SharedPreferences as soon as it is created, and during each Tick, the system calculates my timer in place, simply finding the difference between startTime and the current time.
Now, I tried to make my startTime a Calendar variable and initialized as such:
Calendar startTime = Calendar.getInstance();
and then
elapsedTime = startTime - Calendar.getInstance();
But obviously this does not work.
In a similar project written in C #, I was able to get this to work, albeit using the DateTime variable ... Is there such a way in Android?
If this is too confusing, is there a better way to keep progress in the chronometer?
Please thanks!