|
|
|
@ -0,0 +1,29 @@
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
// 导入Android系统中处理广播接收的类
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
// 导入Android系统中处理上下文环境的类,用于访问应用程序的资源和类
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
// 导入Android系统中处理意图的类,用于描述要执行的动作
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
|
|
// 定义一个名为AlarmReceiver的类,继承自BroadcastReceiver
|
|
|
|
|
// 该类用于接收闹钟触发的广播,并启动闹钟提示界面
|
|
|
|
|
public class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
// 设置Intent的目标类为AlarmAlertActivity
|
|
|
|
|
// 这样当Intent被触发时,会启动AlarmAlertActivity
|
|
|
|
|
intent.setClass(context, AlarmAlertActivity.class);
|
|
|
|
|
|
|
|
|
|
// 添加标志,指示该Activity应该作为新任务启动
|
|
|
|
|
// 当从非Activity的途径(如BroadcastReceiver)启动Activity时,需要设置此标志
|
|
|
|
|
// 因为非Activity的途径启动Activity时,没有现有的Activity栈可以加入
|
|
|
|
|
// 所以需要新建一个栈来容纳即将启动的Activity
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
|
|
|
|
|
// 使用Context的startActivity方法启动Intent指定的Activity
|
|
|
|
|
// 这里启动的是AlarmAlertActivity,用于显示闹钟提示界面
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
}
|