last day (15 days later) » 

11:31
1
A: A new instance of timer created everytime I press a button

ChuckyOnly skimmed this, but after Googling Timer, saw the cancel method, which says: When a timer is no longer needed, users should call cancel(), which releases the timer's thread and other resources. Timers not explicitly cancelled may hold resources indefinitely.

But where to call the Cancel? That is the question mate! Its all happening inside a button click!
Presumably right before the new creation, like so:

if(tripTimeCounter!=NULL)
tripTimeCounter.cancel();
tripTimeCounter = new CountDownTimer(60 * 1000, 1000) {... etc.
Does work, only the seconds get reset. Another day of mind boggling!
Try tripTimeCounter.purge() right after and see if that clears it up.
The method purge() is undefined for the type CountDownTimer.
11:31
You are correct, sorry about that. What do you mean by only the seconds getting reset? Just so that I understand correctly.
Time Elapsed: 00:00:00(HH:MM:SS) after the above, if(tripTimeCounter!=NULL) tripTimeCounter.cancel(); Only the SS part seems to refresh.
Sorry, I'm still having difficulty understanding
Well the trip counter is executing in HH > Hours
MM> Minutes
SS: For seconds
after canceling it the value in Seconds is reset, however the Minutes part is not effected.
You getting my point?
right
so it goes to 60 or 59s?
Dont worry, I will be glad to explain
It goes to 60..
11:36
I see
Actualy on the display, it counts till 58, pauses for a second or so and updates the minute.
However I had programmed it with a 60
tripTimeCounter = new CountDownTimer(60 * 1000, 1000)
This is a tough one.
Its boggling me since two days!
Can you paste the new code
and be sure to hit ctrl+k before pasting so it formats.
11:53
Sure
private View.OnClickListener but = new View.OnClickListener() {

		public void onClick(View v) {
			if (isOnline() == true) {
				if (tripTimeCounter != null) {
					tripTimeCounter.cancel();
					// tripTimeCounter.purge();
					// tripTimeCounter.start();
				}
				// tripTimeCounter.cancel();

				tripTimeCounter = new CountDownTimer(60 * 1000, 1000) {

					@Override
					public void onFinish() {
						// TODO Auto-generated method stub
						repeatCounter = repeatCounter + 1;
						start();
private static String formatInterval(final long l) {
		final long hr = TimeUnit.MILLISECONDS.toHours(l);
		final long min = TimeUnit.MILLISECONDS.toMinutes(l
				- TimeUnit.HOURS.toMillis(hr));
		final long sec = TimeUnit.MILLISECONDS.toSeconds(l
				- TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min));
		final long ms = TimeUnit.MILLISECONDS.toMillis(l
				- TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min)
				- TimeUnit.SECONDS.toMillis(sec));
		return String.format("%02d:%02d:%02d", hr, min, sec, 0);
12:25
I will have to leave now, will catch up with you soon mate!
Takecare and thank you for the guidance!
 
2 hours later…
14:38
NP, let me know how you get on

last day (15 days later) »