You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xiaomi/ui/AlarmReceiver.java

40 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* 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类继承自BroadcastReceiverBroadcastReceiver用于接收系统发送的广播消息在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);
}
}