Android 在后台倒数计时器 [英] Android count down timer in background

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

问题描述

我有一个 Android 应用程序,它管理一个倒数计时器(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.

我现在的问题是,当我按下主页按钮或启动另一个应用程序时,应用程序/计时器不会在后台运行.所以我怀疑我必须做一项服务,但如何做?同事对我说,当设备被锁定时,我必须做一些特别的事情才能让计时器继续.我想在到达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.

最好的方法是什么?

推荐答案

您必须创建 CountDownTimer 类并从 Service 类扩展它.通过这样做,您的活动将成为一项服务,即使您关闭它也会在后台运行应用程序或屏幕无关紧要,它只是在后台执行您分配给它的任务.

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 .

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

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