Reputation: 1320
How to create a timer runed in the background and display one second of a second in the TextView
dynamically in MainActivity.Whatever I exit app or leaving the MainActivity
,the timer also keep on.
I thinked that I can use service
and BroadcastReceiver
or using Handler
and Thread
.But I can't solve it.
Upvotes: 1
Views: 274
Reputation: 1320
I have thinked a solution; Thread
+Handler
; EveryTime enter ther MainActivity
we just set the time interval
= EndTime
-System.currentTimeMillis()
;
Upvotes: 0
Reputation: 2321
Having an always-on service to simply count up seconds is a bad idea, it'll waste battery life and could be killed at any time.
What you could do is something like this:
Upvotes: 2