Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer across the multiple activities

i have an android app with several activities. I need to start a timer when the first activity starts and end the timer when the last activity starts and show the elapsed time. How can i use Asynctask to do this.

like image 220
user377941 Avatar asked Feb 04 '26 22:02

user377941


1 Answers

Subclass Application, declare a public static long started; which will be assigned to System.currentTimeMillis(); by the first Activity in onCreate() or onResume(). Have the last Activity read the value and calculate delta.
If you absolutely want to use AsyncTask (which I think is irrelevant in this case), you'll at least need a mediatory Service for that.

like image 170
yanchenko Avatar answered Feb 07 '26 13:02

yanchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!