这个例子介绍了如何在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. 15.Subtree of Another Tree(判断一棵树是否为另一颗树的子树)

    Level:   Easy 题目描述: Given two non-empty binary trees s and t, check whether tree t has exactly the s ...

  2. ssm中实现excle导入导出

    1 pom.xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-oox ...

  3. Linode安装环境

    Ubuntu 18 密码:Fenghaiyan35 netstat -plnt                           //查看所有文件 sudo apt-get install apac ...

  4. 【STL基础】deque

    deque (double-ended queue) 构造函数: //default: deque<T> d; //空的vector //fill: deque<T> d(n) ...

  5. C语言抽象数据类型ADT

    根据编程的问题匹配合适的数据类型.数据项连接构成了链表,定义了一个结构代表单独的项.设计了一些方法把一系列结构构成一个链表.本质上,我们使用C语言的功能设计了一种符合程序要求的新的数据类型.但是上述的 ...

  6. P5221 Product(莫比乌斯反演)

    CYJian的新春虐题赛- 比赛详情 [题目链接] https://www.luogu.org/problemnew/show/P5221 求 \(\prod_{i=1}^{N}\prod_{j=1} ...

  7. saltstack一键部署高可用

    一健推送apache [root@server1 minions]# cd /etc/salt/ [root@server1 salt]# vim master [root@server1 salt] ...

  8. 如何避免遗漏bug

    bug遗漏,我想这个是很多公司很多人头痛的一个问题.众所周知,bug是不可能被完全消灭的,当然也就意味着在发布前不能被全部找出来.于是乎当项目发布后,或多或少都会出现bug遗漏的现象,即使发布初期没有 ...

  9. 服务器报nginx: [warn] conflicting server name "blog.xueyi.com" on 0.0.0.0:80, ignored

    nginx: [warn] conflicting server name "blog.xueyi.com" on 0.0.0.0:80, ignored 修改nginx配置参数后 ...

  10. 压测工具 ab jmeter

    apach ab|abs ab  -n -c xxx.html/js/css jmeter siege 用途:测试分布式锁是否有效, 测试java Lock是否使用正确,测试接口吞吐量