AlarmManager对象关闭后在手机上 [英] AlarmManager object after turning off and on the phone

查看:169
本文介绍了AlarmManager对象关闭后在手机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我设置闹钟

In my app, I set an alarm

AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
...
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
...
alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);

它正常工作,除非我关闭和开启手机。

It works fine unless I turn off and turn on the phone.

要更具体,让我们说,在10点20分,我将闹铃设定为10:22,我关闭和打开手机上的10:21,报警器将无法正常工作。

To be more specific, let's say at 10:20, I set an alarm to 10:22 and I turn off and turn on the phone at 10:21, alarm won't work.

可能是什么问题?是那个pendingIntent的广播问题上有或者我应该设置alarmManager对象的一些标志使其在这样的条件下工作?

What might be the problem? Is that a broadcast issue of the pendingIntent there or should I set some flags of the alarmManager object for it to work in such conditions?

推荐答案

有关 AlarmManager 说:

注册警报被保留,而该设备是睡着了(并且可以选择唤醒设备,如果在这段时间内熄灭),但如果它被关闭并重新启动将被清除。

Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

看来,包括违约Android上的AlarmClock确实,即使在重新启动后正常工作。

It seems that the AlarmClock included by default by Android does work even after a reboot.

在的方式,让你的报警器重新启动后的工作,是启动应用程序的启动完成,并重新建立所有的大报警与AlarmManager。 (事实上​​,你可能希望只安装使用广播的报警,不能启动您的应用程序)

On way to keep your alarms working after a reboot, is to start your application on boot completed and set up all the alams again with the AlarmManager. (In fact you may want to just setup your alarms using a Broadcast, not start your app)

这里是一个计算器问题,处理关于吃午饭的应用程序启动。

Here is a StackOverflow question dealing about lunching an app on startup.

您婉也检查出了默认的AlarmClock从源读取做到这一点。 你可以阅读从这里 下载

You wan also check out how the default AlarmClock does this by reading from the source. You can read and download it from here

这篇关于AlarmManager对象关闭后在手机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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