BroadcastReceiver onReceive open dialog(BroadcastReceiver onReceive 打开对话框)
问题描述
我正在使用 BroadcastReceiver
构建一个 android 应用程序,并且我想在 onReceive
启动时显示一个对话框.我想在手机上显示对话框(无论用户身在何处,都向用户显示对话框,例如收到消息时的 whatsapp 对话框).
I'm building an android application with BroadcastReceiver
and I want to show a dialog when onReceive
starts.
I want to show the dialog on the phone (show the user a dialog no matter where he is, like the whatsapp dialog when you get a message).
我该怎么做?
谢谢!
推荐答案
如果你想在广播接收器的 onReceive
内部显示一个对话框,你可以在广播接收器内部启动一个透明的活动一个警告对话框,从不调用 setContentView()
.该活动将具有透明视图,并且只会显示警报对话框.来源: 显示系统重启后广播接收器中的警报对话框
If you want to show a dialog from inside your onReceive
of the BroadcastReceiver, inside your broadcast receiver you may start a transparent activity with an alert dialog and NEVER called setContentView()
. The activity will have an transparent view and only the alert dialog will show.
Source: show an alert dialog in broadcast receiver after a system reboot
有很多类似的帖子都在谈论这个话题.有关代码示例和其他评论,请参阅以下问题:
There are many similar posts which talk about this topic. See below questions for code samples and other reviews on the same:
BroadcastReceiver 中的 AlertDialog??能做到吗?
如何从 BroadcastReceiver 发出警报对话框上课?
如何显示来自 Android 广播接收器的对话框?
如何从 BroadcastReceiver 设置 Alertbox
希望这会有所帮助.
这篇关于BroadcastReceiver onReceive 打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:BroadcastReceiver onReceive 打开对话框


基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01