在重新启动重置警报 [英] Resetting alarms on reboot

查看:151
本文介绍了在重新启动重置警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户可以创建不同的警报。所以它的用户时,请报警,他可以保留多个报警和我保持数据库中所有预定的报警,并显示给用户作进一步参考。下面是我的code。

User can create different alarms. So it's up to user when to keep alarm and he can keep multiple alarms and I maintain all the scheduled alarms in a database and show to the user for further reference. Below is my code.

if("CREATEONCE".equals(strparam1))
    {
         am.set(AlarmManager.RTC_WAKEUP, l2, pi);// l2 is time in millis
    }else if("CREATEREPEAT".equals(strparam1))
        {

    am.setRepeating(AlarmManager.RTC_WAKEUP, l2, 86400000 , pi); //l2 is time in millis
    }

因此​​,这是code这台报警。用户可以设置多个闹钟。比如他一直在上午07时这一次,上午08时00 一次和 9.00报警我dialy 。因此,对于一旦报警的code去,如果块和重复每日中,code去别的,如果挡在了code。

So this is the code which sets the alarms. User can set multiple alarms. For example he keeps an alarm for 7.00 am for once, 8.00 am for once and 9.00 am dialy. So, for once alarms the code goes to if block and for repeat daily, the code goes to else if block in the code.

如果上述3报警由用户在上午6时设置。如果他设置的报警后,立即重新启动他的装置,整个警报不触发。

If the above 3 alarms are set by user at 6.00 am. If he reboots his device immediately after setting the alarms, the entire alarms don't trigger.

所以我已阅读关于这个像<一个多帖子href=\"http://stackoverflow.com/questions/12034357/does-alarm-manager-persist-even-after-reboot?rq=1\">post1, POST2 。他们都只是给了使用广播接收器来知道,设备将重新启动。广播接收器接收后暗示该设备重新启动,我需要通过获得来自SQLite数据库的信息,以使所有的报警工作,再重复上述code?如果是这样,有人可以帮我做,从广播接收器的方式吗? code片段是AP preciated

So I have read many posts regarding this like post1, post2. They all just gave to use broadcast receiver to know that device is rebooted. After the broadcast receiver receives a hint that device is rebooted, do I need to repeat above code again by getting the info from sqlite database to make all the alarms work? If so, can someone help me the way to do that from the broadcast receiver? Code snippets are appreciated

假设如果用户设置 50报警,不会是一个长期的过程来获得所有50个报警信息,并重新设置?

Suppose if the user sets 50 alarms, wouldn't it be a long process to get the info of all the 50 alarms and set them again?

推荐答案

我不知道你是如何存储你报警。但我建议就足够了设立最早的到来报警系统级警报。然后,一旦被触发,下一个最快触发报警重新设置报警。

I don't know how you are storing your alarms. But I suggest it would suffice to set up a system level alarm for the earliest coming alarm. Then once that is triggered, set up the alarm again for the next soonest triggering alarm.

我建议把你的电话AlarmSetting一个服务,然后从广播接收器调用它。

I suggest putting your AlarmSetting call in a service and then call it from a broadcast receiver.

public class AlarmResetReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
       //your code to set up alarms
    }
}

有也取决于要在你的清单重新设定你的报警了其他条件

There are also other conditions upon which you want to set your alarms up again in your manifest

<receiver android:name=".receivers.AlarmResetReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.TIME_SET" />
            <action android:name="android.intent.action.TIMEZONE_CHANGED" />
            <action android:name="android.intent.action.LOCALE_CHANGED" />
        </intent-filter>
    </receiver>

这篇关于在重新启动重置警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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