本文介绍了如何使天文钟在后台运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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!

这篇关于如何使天文钟在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 17:43
查看更多