3

如果我想在用户直接单击后退按钮时将该计时器置于后台,我现在正在使用意图撤销 android 中的计时器,那么我该怎么做?然后当我看到后台应用程序正在运行时,它应该可以工作并且可以放在前面。

4

1 回答 1

2

The problem is that if you define the counter in your Activity, the counter is bound to the Activity life-cycle. In order to workaround this, you can create your counter in a Service and just visualize the value in Activity.

There are also several techniques which you can use when defining the counter inside the Activity. Using SystemClock to track the time in your Activity in onStart() and onStop() for example, you can manually calculate the difference between those two values and adjust accordingly your counter.

于 2012-07-03T11:46:45.310 回答