问题描述
我在Activity
中(1)A Chronometer
,并且运行良好.我单击Button
并开始Chronometer
时间计数.
I have in a Activity
(1) A Chronometer
and is running fine. I click a Button
and starts Chronometer
time count.
我正在尝试将得分Chronometer
更改为Activity
(2),但没有成功.
I'm trying to keep the score Chronometer
changing Activity
(2) but without success.
在此新的Activity
(2)中,布局Chronometer
没有一个组件.我试图将Activity
(1)的Chronometer
对象传递给另一个Activity
(2),并继续计数,但即使使用该计时码表并给出一个新的start()
,也不会继续计时.我试图通过Intent.putExtra()
传递组件Chronometer
并创建一个内存类.
In this new Activity
(2) does not have the layout Chronometer
one component.I tried to pass the Chronometer
object of Activity
(1) to the other Activity
(2) and continue the count but continues even taking this Chronometer and giving a new start()
does not count the time.I tried to pass the component Chronometer
via Intent.putExtra()
and creating a memory class.
我甚至试图在不可见的布局中创建Activity
(2)一个Chronometer
,并且仅传递Chronometer.getBase()
的值并给出一个start()
,这没有计算时间.在Activity
中,应继续记录时间,并返回到Activity
(1),Chronometer
应该是可见的经过时间.
I tried to even create the Activity
(2) a Chronometer
in invisible layout and pass only the value of Chronometer.getBase()
and give a start()
, is not counting the time.In Activity
(2) should continue recording the time and return to the Activity
(1) Chronometer
should be visible elapsed time.
Activity
(1)和(2)与finish()
一起消亡.
The Activity
(1) and (2) die with the finish()
.
推荐答案
感谢您的回复!我曾尝试过这种媒介,但没有成功.实际上,我对代码进行了更好的分析,发现自己正在破坏自己.将计时器设置为开始计时后,便创建了一个新的计时表实例.因此它不占.并要利用它们的更多代码计时手段:
Thanks for the reply! I had tried before this medium but without success. In fact I analyzed my code better and saw that I was sabotaging myself. A new instance of Chronometer was created after setting it to start counting. So it does not accounted for. and taking advantage would have to use their means of more this code timing:
long restartTime = getIntent().getLongExtra(Constantes.TIME, 0) + SystemClock.elapsedRealtime();
这是在将当前的计时器设置为有问题的计时器之前的活动时.
This was when set the current getBase the Chronometer in question the previous Activity.
将Activity命名为以下putExtra()的步骤:
And step for the Activity to be called the following putExtra():
long valueChrono = chronometer.getBase()
- SystemClock.elapsedRealtime();
谢谢您,遇到任何问题!
Thank you and sorry for any problems!
这篇关于如何使天文钟在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!