Android中关于Notification及NotificationManger的详解

前端技术 2023/09/04 Android

Android状态栏提醒

在Android中提醒功能也可以用AlertDialog,但是我们要慎重的使用,因为当使用AlertDialog的时候,用户正在进行的操作将会被打断,因为当前焦点被AlertDialog得到。我们可以想像一下,当用户打游戏正爽的时候,这时候来了一条短信。如果这时候短信用AlertDialog提醒,用户必须先去处理这条提醒,从而才能继续游戏。用户可能会活活被气死。而使用Notification就不会带来这些麻烦事,用户完全可以打完游戏再去看这条短信。所以在开发中应根据实际需求,选择合适的控件。

步骤:

一、添加布局对象

复制代码 代码如下:

<Button
android:id=\"@+id/showButton\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"showNotification\" />

<Button
android:id=\"@+id/cancelButton\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:text=\"cancelNotification\" />

本文地址:https://www.stayed.cn/item/9113

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。