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的更多相关文章

  1. 浏览器桌面通知--Notification

    前言 最近项目上要用到浏览器桌面通知,之前虽然知道有这个东西,但是一直没有用过,借此机会了解下桌面通知的机制,在此分享下. 1.权限 首先需要明确的是,不是所有网页都可以发桌面通知的,不然不得烦死,那 ...

  2. 向通知栏发送通知点击跳转并传递数据(PendingIntent)传递数据

    // 为发送通知的按钮的点击事件定义事件处理方法 public void send() {///// 第一步:获取NotificationManager NotificationManager nm ...

  3. Android中的通知—Notification 自定义通知

    Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

  4. iOS的通知Notification

    这里是不同的对象之间的通知, 不是本地通知. 一开始玩, 很挠头, 后来发现原来只是对象init的过程出了问题. 首先, 新建一个简单的单controller的工程. 然后打开它的ViewContro ...

  5. Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。

    常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...

  6. Swift - 使用NSNotificationCenter发送通知,接收通知

    转载自:http://www.mamicode.com/info-detail-1069228.html 标签: 1,通知(NSNotification)介绍 这里所说的通知不是指发给用户看的通知消息 ...

  7. 通知栏发送消息Notification(可以使用自定义的布局)

    一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notifica ...

  8. 状态栏通知Notification的简单使用

    今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...

  9. 通知 Notification 详解

    效果 通知栏-刚收到通知时 通知栏-收到通知几秒后 标准视图 大视图-下滑前是标准视图 大视图-下滑后显示大视图 自定义通知 讲解 Notification,俗称通知,是一种具有全局效果的通知,它展示 ...

随机推荐

  1. perl 调用按钮输出到文本框

    sub push_b4 { #$txt -> insert('end'); #select $txt; system("expect c:\\\\expect.txt >expe ...

  2. C# 导出CSV功能记录下

    异常问题1: 如 机构编号 导出城CSV后,前面的四个0000不显示了, 解决办法 输出格式变为 =" 异常问题2: PPMABAT01:/MABATAPS/usr/ma_batas > ...

  3. hadoop结构出现后format变态

    14/07/10 18:50:47 FATAL conf.Configuration: error parsing conf file: com.sun.org                     ...

  4. LeetCode Day2

    Power of Two /** * LeetCode: Power of Two * Given an integer, write a function to determine if it is ...

  5. ubuntu高版本环境变量问题

    在ubuntu较高的版本(博主使用的是14.10)下,可以在/etc/environment中配置环境变量,这个环境变量可能会覆盖用户~/.bashrc中配置的环境变量,这个应该引起注意.

  6. Devexpress之barManager控件属性

    隐藏菜单栏左边的竖线和右边的箭头? 1.隐藏菜单栏上右边的箭头属性设置:OptionsBar=>>AllowQuickCustomization=False 2.隐藏菜单栏左边的竖线属性设 ...

  7. T-SQL事务

    事务 订火车票的时候,下一个订单,这个订单中,包含多个购买信息,要么全部执行,要么全部不执行,合作事务就是来处理这种模型的一种机制. --关键字:transaction 或 tran 简写形式 --开 ...

  8. 深入理解 Javascript 面向对象编程(转)

    一:理解构造函数原型(prototype)机制 prototype是javascript实现与管理继承的一种机制,也是面向对象的设计思想.构造函数的原型存储着引用对象的一个指针,该指针指向与一个原型对 ...

  9. 常用WebService收集

    尊重原著作:本文转载自http://www.cnblogs.com/tianguook/archive/2010/09/29/1838469.html 天气预报Web服务,数据来源于中国气象局Endp ...

  10. iOS开发那些事儿(四)the dark arts of the Objective-C runtime

    一."Black Magic":Method Swizzling 利用 Runtime 特性把一个方法的实现与另一个方法的实现进行替换,也可以用runtime的四维理解——修改Di ...