Android的倒计时器在后台计时器、后台、Android

2023-09-13 01:39:00 作者:烟火色.

我有一个Android应用程序与管理countdowntimer(类CountDownTimer),这显示在应用程序屏幕上,显示有多少时间留给到达00:00。

I have an Android app with manage a countdowntimer (class CountDownTimer) that it is shown in app screen, to show how much time left to arrive 00:00.

我现在的问题是,当我preSS home键或当我启动另一个应用程序的应用程序/计时器不会在后台运行。所以我怀疑我必须做一个服务,但如何?同事说,我认为我必须做一些特别的当设备被锁定为了使定时器继续。我要醒来的时候到达0。

My problem now is that when I press home button or when I launch another app the app/timer does not run in the background. So I suspect I must do a service, but how? Colleagues have said to me that I must do something special for when the device gets locked in order for the timer to continue. I want to wake up when arrived to 0.

什么是做到这一点的最好方法是什么?

What is the best way to do this?

推荐答案

您必须创建CountDownTimer类和服务类扩展它。 这样的活动变成一个服务,它运行在即使你关闭背景 应用程序或屏幕不管从它只是没有分配给它在后台的任务。

You must create your CountDownTimer class and extend it from Service class. By doing so your activity becomes a service and it runs in the background even if you close the application or the screen it doesnt matter it just does the task that you assign to it in the background .