notif.setLatestEventInfo(this, from, message, contentIntent);
// We'll have this notification do the default sound, vibration, and led.
// Note that if you want any of these behaviors, you should always have
// a preference for the user to turn them off.
notif.defaults = Notification.DEFAULT_ALL;
// Note that we use R.layout.incoming_message_panel as the ID for
// the notification. It could be any integer you want, but we use
// the convention of using a resource id for a string related to
// the notification. It will always be a unique number within your
// application.
nm.notify(R.string.imcoming_message_ticker_text, notif);
}
仅有以上代码是不够的,通常,Android会把应用程序的所有的Activity都看做是应用程序UI流的一部分,因此只是简单的启动这种通知Activity会导致它跟普通的应用程序回退堆栈混杂在一起。要保证它的正确的行为,在清单文件中必须给这个Activity声明属性:android:launchMode=”singleTask”、android:taskAffinity=””和android:excludeFromRecents=”true”。下例是一个完整的Activity的声明。
<activity android:name=".app.IncomingMessageInterstitial"
android:label="You have messages"
android:theme="@style/ThemeHoloDialog"
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true">
</activity>
从这个初始的Activity中启动其他的Activity时必须要小心,因为,它不是应用程序的顶层Activity,也不是最近显示的那个Activity,并且在任何要显示带有新数据的通知的时点都要重新启动。最好的方法是从通知Activity中启动的其他任何Activity都在它们自己的任务中。使用这种方法时必须确保新的任务与当前正在退出的应用程序的任务的状态进行正确的交互。这种方式本质上跟之前介绍的Email应用的通知方式一样的。下例中的代码使用之前例子中的makeMessageIntentStack()方法,然后处理点击事件,完成应用程序之间的切换: /**
* Perform a switch to the app. A new activity stack is started, replacing
* whatever is currently running, and this activity is finished.
*/
void switchToApp() {
// We will launch the app showing what the user picked. In this simple
// example, it is just what the notification gave us.
CharSequence from = getIntent().getCharSequenceExtra(IncomingMessageView.KEY_FROM);
CharSequence msg = getIntent().getCharSequenceExtra(IncomingMessageView.KEY_MESSAGE);
// Build the new activity stack, launch it, and finish this UI.
【Android开发API】用户界面 - 状态通知 - Status Notifications_计算机软件及应用_IT/计算机_专业资料。 eoe 移动开发者社区 www.eoe.cn 负责?:Kobehonghai 原文...
【Android开发API】用户界面 - Toast通知 - Toast Notifications_计算机软件及应用_IT/计算机_专业资料。eoe 移动开发者社区 www.eoe.cn 原文链接:http://...
【Android开发Design】通知 - Notifications 1_制度/规范_工作范文_应用文书。... 要让产品有好的用户体验... 能让UI设计显得更简约的... 马桶到删除:从...
android用户界面程序设计_IT/计算机_专业资料。淮海工学院计算机工程学院 实验...(可参考文档中 Dev Guide 的帮助主题 Toast Notifications 中的内容) 三、实验...
这个章节描述怎么实现一个基本的 Android 界面.它涉及构建屏幕基本元素,怎么在 xml(定义文件)内定义屏幕, 用你的代码生成, 在不同任务你需要操作你的用户接口. ...
Android用户界面框架 ? MVC模型 ? ? MVC模型中的控制器能够接受并响应程序的外部动作, 如按键动作或触摸屏动作等 控制器使用队列处理外部动作,每个外部动作作为一...
图形用户界面设计 目标学员: 学习目标: Android初级开发者用户界面设计原则 用户界面设计核心概念 对话框 菜单 通知 课程时长: 4学时,180分钟 课程目录 1 2 3 4...
9.Android用户界面UI元素之对话框(Dialog)和通知(Notification)_IT/计算机_专业资料。Android开发教程Softeem Consultancy Service Android用户界面(UI)组件 用户界面( ...
? ? ? ? User Interface(用户界面) View Hierarchy(视图层次) How Android ...(风格与主题) Notifications(通知) ActionBar(活动栏) Drag and Drop(拖拽) ...
热门文档