发送通知:Notification
Intent的主要功能是完成一个Activity跳转到其他Activity或者是Service的操作,表示的是一种
操作的意图。
PendingIntent表示的是暂时执行的一种意图,是一种在产生某一事件之后才进行操作的Intent对象。
面试题:请解释Intent与PendingIntent的区别:
Intent表示立即执行;
PendingIntent表示暂缓执行,遇到特殊条件才执行。
发送通知:Notification
Notification表示一种提示用户操作的组件。
Notification表示的是一个通知,而NotificationManager表示的是一个发送通知的操作类。
在main.xml中:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="#000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#ffffff"
android:text="请看上面的通知!"/>
</LinearLayout>
在MyNotificationDemo.java中:
package com.li.notification;
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MyNotificationDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
NotificationManager notificationManager =
(NotificationManager)super.getSystemService(Activity
.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.pic_m,"来自李叶文的消息",
System.currentTimeMillis()); //立刻发送一个消息
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, super.getIntent(), PendingIntent
.FLAG_CANCEL_CURRENT); //创建了一个PendingIntent对象
notification.setLatestEventInfo(this, "广西", "北海", contentIntent);
notificationManager.notify("LYW",R.drawable.pic_m,notification);
}
}
发送通知:Notification的更多相关文章
- 浏览器桌面通知--Notification
前言 最近项目上要用到浏览器桌面通知,之前虽然知道有这个东西,但是一直没有用过,借此机会了解下桌面通知的机制,在此分享下. 1.权限 首先需要明确的是,不是所有网页都可以发桌面通知的,不然不得烦死,那 ...
- 向通知栏发送通知点击跳转并传递数据(PendingIntent)传递数据
// 为发送通知的按钮的点击事件定义事件处理方法 public void send() {///// 第一步:获取NotificationManager NotificationManager nm ...
- Android中的通知—Notification 自定义通知
Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...
- iOS的通知Notification
这里是不同的对象之间的通知, 不是本地通知. 一开始玩, 很挠头, 后来发现原来只是对象init的过程出了问题. 首先, 新建一个简单的单controller的工程. 然后打开它的ViewContro ...
- Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。
常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...
- Swift - 使用NSNotificationCenter发送通知,接收通知
转载自:http://www.mamicode.com/info-detail-1069228.html 标签: 1,通知(NSNotification)介绍 这里所说的通知不是指发给用户看的通知消息 ...
- 通知栏发送消息Notification(可以使用自定义的布局)
一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notifica ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...
- 通知 Notification 详解
效果 通知栏-刚收到通知时 通知栏-收到通知几秒后 标准视图 大视图-下滑前是标准视图 大视图-下滑后显示大视图 自定义通知 讲解 Notification,俗称通知,是一种具有全局效果的通知,它展示 ...
随机推荐
- 【the service mysql57 failed the most】
异常信息: the the service mysql57 failed the most recent status change request with the messagethe servi ...
- logstash 分析nginx 错误日志
[root@dr-mysql01 frontend-error]# cat logstash_error.conf input { file { type => "zj_fronten ...
- Chapter 1. Hello, Perl/Tk
Chapter 1. Hello, Perl/Tk 内容: Perl/Tk Concepts Some Perl/Tk History Getting Started with Perl/Tk Hel ...
- boost的并发库
thread: http://www.boost.org/doc/libs/1_61_0/libs/thread/ asio: http://www.boost.org/doc/libs/1_61_0 ...
- Tengine笔记1:安装Tengine和Tengine说明
什么是Tengine 官方帮助文档:http://tengine.taobao.org/nginx_docs/cn/ Tengine的安装 新建tengine用户组 groupadd -r n ...
- AJAX提交到Handler.ashx一般处理程序返回json数据 (字符串拼接方式)
<%@ WebHandler Language="C#" Class="Handler" %> using System; using System ...
- C# 3.0 { get; set; } 默认值
.NET Framework 3.5 使用的是 C# 3.0,C# 3.0 有一些新的语言特性,其中有一项就是快捷属性. 之前的写法: private int _id = 0;public int I ...
- Hadoop CLI MiniCluster
CLI MiniCluster Use the climonicluster, users can simply start and stop a single-node hadoop cluster ...
- UIPageViewController跳跃切换的问题
使用的是XHScrollMenu和UIPageViewController来构建5个页面: ViewController1, ViewController2, ViewController3, Vie ...
- 10个原生JavaScript技巧
这些代码片段主要由网友们平时分享的作品代码里面和经常去逛网站然后查看源文件收集到的.把平时网站上常用的一些实用功能代码片段通通收集起来,方便网友们学习使用,利用好的话可以加快网友们的开发速度,提高工作 ...