chronometer

Android: chronometer as a persistent stopwatch. How to set starting time? What is Chronometer “Base”?

风格不统一 提交于 2019-11-27 09:07:04
I do have one service running in the background. Whenever it starts I store in memory the starting time in milliseconds: startingTime = new Date().getTime(); I want to display a chronometer that starts counting when the service starts and never stops until the user presses a button. I want to allow the user to leave the activity rendering the chronometer, do some stuff and then return. But the idea is that when the user returns I dont want the chronometer to go to 0:00 again. Insted I want it to show the exact time that has passed ever since the service has started. I can calculate elapsedTime

Android: chronometer as a persistent stopwatch. How to set starting time? What is Chronometer “Base”?

烈酒焚心 提交于 2019-11-26 17:48:17
问题 I do have one service running in the background. Whenever it starts I store in memory the starting time in milliseconds: startingTime = new Date().getTime(); I want to display a chronometer that starts counting when the service starts and never stops until the user presses a button. I want to allow the user to leave the activity rendering the chronometer, do some stuff and then return. But the idea is that when the user returns I dont want the chronometer to go to 0:00 again. Insted I want it

Android - Get time of chronometer widget

坚强是说给别人听的谎言 提交于 2019-11-26 05:21:37
问题 How to get the time from a Chronometer? I tried getText, getFormat, getBase, etc, but none of them could work. Example code snippet: Chronometer t = (Chronometer)findViewById(R.id.toptime); long time = SystemClock.elapsedRealtime()-t.getBase(); Log.d(null,\"Was: \"+time); //time is not the proper time for some reason - it is a random number between 0 and 50 t.setBase(SystemClock.elapsedRealtime()); t.start(); 回答1: If you look at the source of the Chronometer class, you'll see that it doesn't