问题描述
例如我的应用程序,它会启动并运行服务(这是为了检查数据库的新邮件),但据我所知,你可以有一个 AlarmManager
保持开放的服务如果有未打开。
For example my app, it starts and runs the service(which is meant to check the database for new messages) but as far as I know you can have a AlarmManager
to keep opening the Service if so is not opened.
但你可以有一个 AlarmManager
服务类中,以保持对数据库中检查新的消息?而不是重新打开服务类只是不停地检查数据库?
But can you have aAlarmManager
inside the Service class to keep on checking for new message in the database? Instead of re-opening the Service class just keep checking the database?
我想知道是否有可能有一个AlarmManager服务类中继续检查数据库中的每个X秒,因为该服务将开时,应用程序启动
I want to know if it is possible to have a AlarmManager inside the Service class to keep checking the database every X seconds, because the Service will open when the App is Launched
真正的问题:是否有可能有一个运行方式(服务类中的AlarmManager)检查数据库?
The real question:Is it possible to have a AlarmManager inside the Service class that runs a Method() to check a database?
推荐答案
使用定时器
Timer myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
/**
*
*Do something. CODE HERE
*/
}
}, 0, 30000); //30000 = 30 Seconds Interval.
这篇关于是否有可能有一个服务类中的AlarmManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!