添加每天重复的闹钟,更改日期为2天后再改回来,前面两天的闹钟不会响

本文主要是介绍添加每天重复的闹钟,更改日期为2天后再改回来,前面两天的闹钟不会响,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

添加每天重复的闹钟,更改日期为2天后再改回来,前面两天的闹钟不会响

[DESCRIPTION]


操作步骤:
1. 当前时间为5月30号14:00,设置闹钟为14:05,每天重复
2. 更改系统时间为6月1号,再次更改为5月30号到14:05时,闹钟不会响。
实际结果:
到14:05时,闹钟不会响。


[SOLUTION]


系统时间发生变化的时候,Alarm时间不能随之而变,导致闹钟不响应
麻烦修改文件AlarmStateManager.JAVA。修改fixAlarmInstances 为如下形式:
public static void fixAlarmInstances(Context context) {
/// M: record for duplicated instance, and delete them
HashMap<Long, AlarmInstance> duplicatedInstance = new HashMap<Long, AlarmInstance>();
// Register all instances after major time changes or when phone restarts
// TODO: Refactor this code to not use the overloaded registerInstance method.
ContentResolver contentResolver = context.getContentResolver();
for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
/// M: record for duplicated instance, and delete them @{
if (duplicatedInstance.get(instance.mAlarmId) == null) {
duplicatedInstance.put(instance.mAlarmId, instance);
} else {
// Delete current instance
AlarmInstance.deleteInstance(contentResolver, instance.mId);
continue;
}
/// @}
/// M: Fix the alarm when time changed
instance = getFixedAlarmInstance(context, instance);
AlarmStateManager.registerInstance(context, instance, false);
}
AlarmStateManager.updateNextAlarm(context);
}
并添加方法:
/** M: Update the alarmInstances who can be set a nearly time @{ */
private static AlarmInstance getFixedAlarmInstance(Context context, AlarmInstance
instance) {
ContentResolver resolver = context.getContentResolver();
Alarm alarm = Alarm.getAlarm(resolver, instance.mAlarmId);
Calendar currentTime = Calendar.getInstance();// the system's current time
// Generate the new instance use the alarm's rule
AlarmInstance newInstance = alarm.createInstanceAfter(currentTime);
Calendar newTime = newInstance.getAlarmTime();// the new instance's time
Calendar alarmTime = instance.getAlarmTime();// the original instance's time
// If the new instance's time is before the original instance's time
// then we can use the new instance's year,month and day with original instance's
// hour and minutes, so that we can keep all the state of the alarm
if (newTime.before(alarmTime)) {
// use the new instance time, update the year,month and day
int newYear = newTime.get(Calendar.YEAR);
int newMonth = newTime.get(Calendar.MONTH);
int newDay = newTime.get(Calendar.DAY_OF_MONTH);
alarmTime.set(Calendar.YEAR, newYear);
alarmTime.set(Calendar.MONTH, newMonth);
alarmTime.set(Calendar.DAY_OF_MONTH, newDay);
// if the alarmTime is still before currentTime, then add a day
while (alarmTime.before(currentTime)) {
alarmTime.add(Calendar.DAY_OF_MONTH, 1);
}
instance.setAlarmTime(alarmTime);
AlarmInstance.updateInstance(resolver, instance);
}
return instance;
}
/** @} */


这篇关于添加每天重复的闹钟,更改日期为2天后再改回来,前面两天的闹钟不会响的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/300844

相关文章

每天认识几个maven依赖(ActiveMQ+activemq-jaxb+activesoap+activespace+adarwin)

八、ActiveMQ 1、是什么? ActiveMQ 是一个开源的消息中间件(Message Broker),由 Apache 软件基金会开发和维护。它实现了 Java 消息服务(Java Message Service, JMS)规范,并支持多种消息传递协议,包括 AMQP、MQTT 和 OpenWire 等。 2、有什么用? 可靠性:ActiveMQ 提供了消息持久性和事务支持,确保消

poj2406(连续重复子串)

题意:判断串s是不是str^n,求str的最大长度。 解题思路:kmp可解,后缀数组的倍增算法超时。next[i]表示在第i位匹配失败后,自动跳转到next[i],所以1到next[n]这个串 等于 n-next[n]+1到n这个串。 代码如下; #include<iostream>#include<algorithm>#include<stdio.h>#include<math.

poj3261(可重复k次的最长子串)

题意:可重复k次的最长子串 解题思路:求所有区间[x,x+k-1]中的最小值的最大值。求sa时间复杂度Nlog(N),求最值时间复杂度N*N,但实际复杂度很低。题目数据也比较水,不然估计过不了。 代码入下: #include<iostream>#include<algorithm>#include<stdio.h>#include<math.h>#include<cstring

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

学习记录:js算法(二十八):删除排序链表中的重复元素、删除排序链表中的重复元素II

文章目录 删除排序链表中的重复元素我的思路解法一:循环解法二:递归 网上思路 删除排序链表中的重复元素 II我的思路网上思路 总结 删除排序链表中的重复元素 给定一个已排序的链表的头 head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。 图一 图二 示例 1:(图一)输入:head = [1,1,2]输出:[1,2]示例 2:(图

C# 防止按钮botton重复“点击”的方法

在使用C#的按钮控件的时候,经常我们想如果出现了多次点击的时候只让其在执行的时候只响应一次。这个时候很多人可能会想到使用Enable=false, 但是实际情况是还是会被多次触发,因为C#采用的是消息队列机制,这个时候我们只需要在Enable = true 之前加一句 Application.DoEvents();就能达到防止重复点击的问题。 private void btnGenerateSh

MySQL脏读、不可重复读、幻读(虚读)

事务的特性: 原子性:指处于同一个事务中的多条语句是不可分割的。一致性:事务必须使数据库从一个一致性状态变换到另外一个一致性状态。比如转账,转账前两个账户余额之和为2k,转账之后也应该是2K。隔离性:指多线程环境下,一个线程中的事务不能被其他线程中的事务打扰持久性:事务一旦提交,就应该被永久保存起来。 事务隔离性问题: 如果不考虑事务的隔离性,会出现以下问题: 脏读:指一个线程中的事务读取到

javaScript日期相加减例子

当前时间加上2天 var d = new Date(“2015-7-31”); d.setDate(d.getDate()+2); var addTwo=d.getFullYear()+”年”+(d.getMonth()+1)+”月”+d.getDate()+”日”; “控制台输出===============”+”当前日期加2天:”+addTwo; 使用这种方法,月份也会给你计算.

如何保证android程序进程不到万不得已的情况下,不会被结束

最近,做一个调用系统自带相机的那么一个功能,遇到的坑,在此记录一下。 设备:红米note4 问题起因 因为自定义的相机,很难满足客户的所有需要,比如:自拍杆的支持,优化方面等等。这些方面自定义的相机都不比系统自带的好,因为有些系统都是商家定制的,难免会出现一个奇葩的问题。比如:你在这款手机上运行,无任何问题,然而你换一款手机后,问题就出现了。 比如:小米的红米系列,你启用系统自带拍照功能后

【第0006页 · 数组】寻找重复数

【前言】本文以及之后的一些题解都会陆续整理到目录中,若想了解全部题解整理,请看这里: 第0006页 · 寻找重复数         今天想讨论的一道题在 LeetCode 上评论也是颇为“不错”。有一说一,是道好题,不过我们还是得先理解了它才算真正的好题。这里我们展示一种使用二进制的做法,希望能帮到你哟! 【寻找重复数】给定一个包含 n + 1 个整数的数组 nums ,其数字都