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.
bird/src/net/micode/notes/ui/AlarmReceiver.java

46 lines
2.1 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.
*/
/*
* AlarmReceiver类 - 用于处理闹钟广播接收
* 当接收到闹钟相关的广播时该类会启动一个指定的Activity
*
* extends BroadcastReceiver: 继承自Android的BroadcastReceiver类
*/
package net.micode.notes.ui; // 定义该类的包路径
import android.content.BroadcastReceiver; // 导入BroadcastReceiver类用于接收广播
import android.content.Context; // 导入Context类用于获取应用环境
import android.content.Intent; // 导入Intent类用于启动活动和传递数据
public class AlarmReceiver extends BroadcastReceiver { // 定义AlarmReceiver类继承自BroadcastReceiver
/*
* onReceive方法 - 系统调用的接收广播的方法
* 当接收到广播时该方法会被调用然后启动AlarmAlertActivity
*
* @param context 上下文对象,提供了调用环境的信息
* @param intent 包含广播的内容
*/
@Override
public void onReceive(Context context, Intent intent) { // 重写onReceive方法当接收到广播时执行
// 设置Intent的类以便启动AlarmAlertActivity
intent.setClass(context, AlarmAlertActivity.class); // 设置Intent的目标Activity为AlarmAlertActivity
// 添加标志表示在一个新的任务中启动Activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 添加标志确保Activity在一个新的任务中启动
// 根据设置的Intent启动Activity
context.startActivity(intent); // 启动AlarmAlertActivity
}
}