/* * 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,用于接收广播消息,并在接收到广播后进行相应的操作,这里主要是启动相关的Activity public class AlarmReceiver extends BroadcastReceiver { // 重写BroadcastReceiver的onReceive方法,当该广播接收器接收到广播时,此方法会被调用,用于处理具体的业务逻辑 @Override public void onReceive(Context context, Intent intent) { // 将传入的Intent的目标组件设置为AlarmAlertActivity.class,也就是指定当这个广播触发后,要启动的Activity是AlarmAlertActivity intent.setClass(context, AlarmAlertActivity.class); // 给Intent添加一个标志位,FLAG_ACTIVITY_NEW_TASK,表示以新任务的形式启动Activity。 // 这通常是在从广播接收器启动Activity时需要添加的,因为广播接收器没有自己的任务栈,需要明确告知系统以新任务来启动Activity intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 通过传入的Context对象启动设置好的Activity,使得应用能够从接收到广播的这个逻辑跳转到对应的AlarmAlertActivity,展示闹钟提醒相关的界面等内容 context.startActivity(intent); } }