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.
2Q1/ui/AlarmReceiver.java

37 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.
*/
// 包声明表明该类所在的包名为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);
}
}