且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何提高从BroadcastReceiver的类警告对话框?

更新时间:2023-01-24 13:25:02

在短:是的不可以可以

只有活动的可以创建/显示对话框。事实上,这已被要求超过一次:

Only Activity's can create/show dialogs. In fact, this has been asked more then once:

  • AlertDialog in BroadcastReceiver
  • How can I display a dialog from an Android broadcast receiver?

另外,为什么要启动一个对话框?

Also, why would you want to launch a Dialog?

  • 如果用户不是在您的应用程序(比方说他玩 游戏)和您的对话框弹出,每15分钟,这将是非常 讨厌他。
  • 如果用户在应用程序中,有几个其他的(更好 某些内容被执行适合)的方式来通知他。
  • If the user is not in your application (let's say he's playing a Game) and your Dialog pops up every 15 minutes, this will be very annoying for him.
  • If the user is in your application, there are several other (better suited) ways to notify him that something has been executed.

事实上,你可以创建/显示 吐司 的BroadcastReceiver 。这吐司也将蜜蜂当用户应用程序中的不显示。

In fact, you can create/show a Toast from an BroadcastReceiver. This Toast will also bee shown when the user is not "in your application".

此外,您还可以发送从的BroadcastReceiver 的通知(在屏幕顶部显示在通知酒吧)。如何做到这一点一个教程(它不会从不同你如何做一个活动,但您使用通过上下文 -object从的onReceive - 方法)。

Also, you can send a Notification (shown in the Notification-Bar at the top of your screen) from a BroadcastReceiver. A tutorial on how to do this (it does not differ from how you do it in an Activity, except that you use the passed Context-Object from the onReceive-method).

当用户应用程序中的不是,是(在我看来)最适合解决这个问题的通知也将被显示。

The Notification will also be shown when the user is not "in your application" and is the (in my eyes) best suited solution to this problem.