|
|
|
@ -1,17 +1,15 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
* 版权所有 (c) 2010-2011, MiCode 开源社区 (www.micode.net)
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
* 本文件授权使用 Apache License, Version 2.0(以下简称“许可证”);
|
|
|
|
|
* 除非符合许可证规定,否则不得使用此文件。
|
|
|
|
|
* 您可以从以下网址获取许可证副本:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
* 除非适用法律要求或书面同意,否则根据许可证分发的软件
|
|
|
|
|
* 均按“原样”分发,不附带任何明示或暗示的保证或条件。
|
|
|
|
|
* 有关许可权限和限制的具体语言,请参阅许可证。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 指定类所在的包名
|
|
|
|
@ -22,22 +20,28 @@ import android.content.BroadcastReceiver; // 广播接收器基类
|
|
|
|
|
import android.content.Context; // 提供应用环境信息的类
|
|
|
|
|
import android.content.Intent; // 用于组件间通信的消息传递对象
|
|
|
|
|
|
|
|
|
|
// 定义一个公开类AlarmReceiver,它继承自BroadcastReceiver
|
|
|
|
|
/**
|
|
|
|
|
* AlarmReceiver 类用于接收闹钟提醒广播。
|
|
|
|
|
* 当系统到达设定的闹钟时间时,该接收器会被触发,启动 AlarmAlertActivity 以显示提醒。
|
|
|
|
|
*/
|
|
|
|
|
public class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
// 重写onReceive方法,当接收到广播时调用此方法
|
|
|
|
|
/**
|
|
|
|
|
* 当接收到广播时,调用此方法。
|
|
|
|
|
* 该方法会启动 AlarmAlertActivity 以显示闹钟提醒。
|
|
|
|
|
*
|
|
|
|
|
* @param context 应用上下文
|
|
|
|
|
* @param intent 接收到的广播 Intent
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
// 设置intent的目标组件为AlarmAlertActivity类
|
|
|
|
|
// 这意味着当这个广播接收器接收到广播时,它希望启动AlarmAlertActivity活动
|
|
|
|
|
// 设置 intent 的目标组件为 AlarmAlertActivity
|
|
|
|
|
intent.setClass(context, AlarmAlertActivity.class);
|
|
|
|
|
|
|
|
|
|
// 为intent添加FLAG_ACTIVITY_NEW_TASK标志
|
|
|
|
|
// 这通常用于从非活动上下文中启动活动时,确保活动作为新的任务启动
|
|
|
|
|
// 添加 FLAG_ACTIVITY_NEW_TASK 标志,确保活动作为新的任务启动
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
|
|
|
|
|
// 使用context对象调用startActivity方法来启动由intent指定的活动
|
|
|
|
|
// 由于intent已经被设置为启动AlarmAlertActivity,这行代码的作用就是启动AlarmAlertActivity活动
|
|
|
|
|
// 启动 AlarmAlertActivity 活动
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
}
|