这个例子介绍了如何在Service中使用Notification,相关的类为NotifyingController和NotifyingService。

在Service中使用Notification的基本方法和前一例子相同。我们暂时还没有介绍Service的用法。 Service的基本概念和Windows OS中Service基本相同:没有UI,在后台运行。Notification可以说是Service最好的用来通知用户的方法。后面有专门介绍 Service的用法,这里就不说明了。

NotifyingService实现在一分钟内每隔5秒钟显示一个Notification。图标分别为笑脸,无表情,哭脸:

            for (int i = 0; i < 4; ++i) {
showNotification(R.drawable.stat_happy,
R.string.status_bar_notifications_happy_message);
if (mCondition.block(5 * 1000))
break;
showNotification(R.drawable.stat_neutral,
R.string.status_bar_notifications_ok_message);
if (mCondition.block(5 * 1000))
break;
showNotification(R.drawable.stat_sad,
R.string.status_bar_notifications_sad_message);
if (mCondition.block(5 * 1000))
break;
}
// Done with our work... stop the service!
NotifyingService.this.stopSelf();

【起航计划 025】2015 起航计划 Android APIDemo的魔鬼步伐 24 App->Notification->Notifying Service Controller service中使用Notification的更多相关文章

  1. 【起航计划 028】2015 起航计划 Android APIDemo的魔鬼步伐 27 App->Preferences->Launching preferences 其他activity获取Preference中的值

    前给例子介绍了如何使用PreferenceActivity 来显示修改应用偏好,用户对Preferences的修改自动存储在应用对应的Shared Preferences中. 本例介绍了如何从一个Ac ...

  2. 【起航计划 002】2015 起航计划 Android APIDemo的魔鬼步伐 01

    本文链接:[起航计划 002]2015 起航计划 Android APIDemo的魔鬼步伐 01 参考链接:http://blog.csdn.net/column/details/mapdigitap ...

  3. 【起航计划 037】2015 起航计划 Android APIDemo的魔鬼步伐 36 App->Service->Remote Service Binding AIDL实现不同进程间调用服务接口 kill 进程

    本例和下个例子Remote Service Controller 涉及到的文件有RemoteService.java ,IRemoteService.aidl, IRemoteServiceCallb ...

  4. 【起航计划 031】2015 起航计划 Android APIDemo的魔鬼步伐 30 App->Preferences->Advanced preferences 自定义preference OnPreferenceChangeListener

    前篇文章Android ApiDemo示例解析(31):App->Preferences->Launching preferences 中用到了Advanced preferences 中 ...

  5. 【起航计划 027】2015 起航计划 Android APIDemo的魔鬼步伐 26 App->Preferences->Preferences from XML 偏好设置界面

    我们在前面的例子Android ApiDemo示例解析(9):App->Activity->Persistent State 介绍了可以使用Shared Preferences来存储一些状 ...

  6. 【起航计划 020】2015 起航计划 Android APIDemo的魔鬼步伐 19 App->Dialog Dialog样式

    这个例子的主Activity定义在AlertDialogSamples.java 主要用来介绍类AlertDialog的用法,AlertDialog提供的功能是多样的: 显示消息给用户,并可提供一到三 ...

  7. 【起航计划 012】2015 起航计划 Android APIDemo的魔鬼步伐 11 App->Activity->Save & Restore State onSaveInstanceState onRestoreInstanceState

    Save & Restore State与之前的例子Android ApiDemo示例解析(9):App->Activity->Persistent State 实现的UI类似,但 ...

  8. 【起航计划 035】2015 起航计划 Android APIDemo的魔鬼步伐 34 App->Service->Local Service Controller

    Local Service Controller 是将LocalService当作“Started”Service来使用,相对于”Bound” Service 来说,这种模式用法要简单得多,Local ...

  9. 【起航计划 034】2015 起航计划 Android APIDemo的魔鬼步伐 33 App->Service->Local Service Binding 绑定服务 ServiceConnection Binder

    本例和下列Local Service Controller 的Activity代码都定义在LocalServiceActivities.Java 中,作为LocalServiceActivities ...

随机推荐

  1. 最小生成树+LCA【洛谷 P2245】 星际导航

    [洛谷 P2245] 星际导航 题目描述 sideman做好了回到Gliese 星球的硬件准备,但是sideman的导航系统还没有完全设计好.为了方便起见,我们可以认为宇宙是一张有N 个顶点和M 条边 ...

  2. ubuntu14.04 搭建samba

        1.安装软件      sudo apt-get remove libwbclient0      sudo apt-get remove samba-common      sudo apt ...

  3. [ZJOI2009]函数 BZOJ1432

    题目描述 有n 个连续函数fi (x),其中1 ≤ i ≤ n.对于任何两个函数fi (x) 和fj (x),(i != j),恰好存在一个x 使得fi (x) = fj (x),并且存在无穷多的x ...

  4. freemarker常用标签解释二

    1 assign 指令 使用这个指令你可以创建一个新的变量,或者替换一个已经存在的变量.注意仅仅顶级变量可以被创建/替换(也就是说你不能创建/替换some_hash.subvar,除了some_has ...

  5. Unity 移动 和 旋转 [小结]

    [移动]  Position: 说明: 直接修改位置数据  Translate: 说明: [匀速]朝着一个方向,一直移动. (dir * speed 可以控制速度)适合键盘控制物体上下左右运动 函数: ...

  6. Codeforces Beta Round #87 (Div. 2 Only)-Party(DFS找树的深度)

    A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exa ...

  7. A reader

    A reader lives a thousand lives before he die... The man who never reads lives only one.

  8. day_07 深浅拷贝

    1. 基础数据类型的补充 1字符串的操作: 1.join 把字符串或者列表的的内拼接,拼接成字符串 和split相反--把字符串转换成列表 2.删除 字典和列表在循环中是不能进行删除的,可以在循环中把 ...

  9. SoapUI性能测试

    之前没发现SoapUI可以做性能测试,自己写了两个简单的例子,体验一下它的测试功能. 一.使用控件顺序执行 测试的框架如上图所示,一个TestCase包含Test Steps(具体的测试步骤),Loa ...

  10. EXCEL 导入SQL SERVER 方法

    1.注意:确认是否已安装 AccessDatabaseEngine.exe 2.可视化按提示操作.