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

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

问题描述

我有一个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 .

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

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