Android计时码表 [英] Android Chronometer

查看:249
本文介绍了Android计时码表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在默认时间00:00以外的特定时间启动天文钟?可以设置chronometerObj.setBase(startTime)吗?

ch.setBase(SystemClock.elapsedRealtime()-anylongvalue); ch.start();如果我输入anylongvalue可以设置开始时间吗?

解决方案

计时对象被实例化后,默认设置为现在的基准时间("now"(如从SystemClock.elapsedRealtime()中获得的值).) >

您可以通过调用setBase(<some other value>)更改基准时间(00:00时间).

大概,尽管我还没有尝试过该实验,但是您可以看到自从上次使用setBase(0)启动系统以来经过的时间.

因此,您可以使用计时码表查看过去您对SystemClock.elapsedRealtime()进行的任意调用以来所经过的时间.诀窍是,您需要将值存储在某个位置,即使应用程序和电话状态发生了变化,也可以可靠地将其取回. (例如,参见 Android:天文钟表作为永久秒表.如何设置开始时间?天文钟表的基本"是什么? )

许多答案表明,意图是坚持过去的任意时间.但这充其量只能使手机保持开机状态时计时器保持计时.

我已经在使用数据库,并将我的开始时间存储在该数据库中.我为此创建了一个单列表,并在其中存储了一条记录.我的计时器的开始时间在手机重启后仍然存在.

How to start the chronometer with a specific time other than default 00:00? Is it possible to set chronometerObj.setBase(startTime) ?

ch.setBase(SystemClock.elapsedRealtime()-anylongvalue); ch.start(); can I set start time, if I put anylongvalue?

解决方案

Chronometer object, when instantiated, defaults to the base time being set to now ('now' as in the value you get from SystemClock.elapsedRealtime()).

You can change the base time (00:00 time) by calling setBase(<some other value>).

Presumably, although I haven't tried the experiment, you could see the elapsed time since last system boot using setBase(0).

So you can use chronometer to see the elapsed time since any arbitrary call you made in the past to SystemClock.elapsedRealtime(). The trick is that you need to have stored that value somewhere you can dependably get it back despite app and phone state changes. (See Android: chronometer as a persistent stopwatch. How to set starting time? What is Chronometer "Base"? for example.)

Many answers suggest persisting that arbitrary time-in-the-past in an intent. but, at best, this only keeps the timer counting up while the phone stays on.

I already am using a database and store my starting time in there. I created a one-column table for it and store a single record in it. My starting time for the chronometer survives a phone reboot.

这篇关于Android计时码表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆