|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (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
|
|
|
*
|
|
|
* 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.
|
|
|
*/
|
|
|
|
|
|
// 包声明,表明该类所在的包名为net.micode.notes.ui
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
|
|
|
// AlarmReceiver类继承自BroadcastReceiver,BroadcastReceiver用于接收系统发送的广播消息,在Android中常用于实现各种系统事件的响应逻辑,例如这里用于响应闹钟触发相关的广播。
|
|
|
public class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
|
// 重写BroadcastReceiver的onReceive方法,该方法会在接收到与之匹配的广播时被调用,在此类中主要用于启动与闹钟提醒相关的Activity(即AlarmAlertActivity)。
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
// 通过Intent的setClass方法,将原本传入的意图(intent)的目标类修改为AlarmAlertActivity.class,也就是将广播意图重新定向到用于展示闹钟提醒详细信息的Activity。
|
|
|
intent.setClass(context, AlarmAlertActivity.class);
|
|
|
|
|
|
// 给意图添加FLAG_ACTIVITY_NEW_TASK标志,这是因为BroadcastReceiver接收到广播时所处的上下文环境可能没有与之关联的任务栈(Task),
|
|
|
// 添加该标志可以确保启动的Activity能够在一个新的任务栈中被创建并展示给用户,避免因缺少任务栈而导致启动失败的问题。
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
|
// 使用传入的上下文(context)来启动经过上述设置后的意图对应的Activity,也就是启动AlarmAlertActivity,让其展示闹钟提醒的相关界面,例如提醒内容摘要、操作按钮等,供用户进行后续操作。
|
|
|
context.startActivity(intent);
|
|
|
}
|
|
|
} |