简体   繁体   English

即使应用程序未运行,也会显示警报对话框

[英]Alert dialog display even when the application is not running

I want to notify the user of my app when he receives special news (from my app). 我想在用户收到特殊消息(来自我的应用程序)时通知我的应用程序。 How can i display some kind of a messeage to the user, even if my app is running in the background (or not running at all if possible). 即使我的应用程序在后台运行(或尽可能不运行),我如何向用户显示某种信息。

I want him to be notified by text, and sound. 我希望通过文本和声音通知他。

Thanks. 谢谢。

You need to write a service for doing this. 您需要为此编写服务 Then in your service code use Notification class to show text and sound alerts. 然后,在服务代码中,使用Notification类显示文本和声音警报。

Use Broadcast Receiver , to notify abt some action. 使用Broadcast Receiver ,通知一些动作。 Like updates, sms, or abt indicate when booting of a phone completes,etc... BroadCast Receiver works on the principle of Publisher and Subscriber pattern. 像更新,短信或abt一样,指示电话启动何时完成等。BroadCast Receiver遵循发布者和订阅者模式的原理工作。

If your app is not running and you want to do something you'll need some kind of broadcast receiver to receive a trigger. 如果您的应用未运行,并且想要执行某些操作,则需要某种广播接收器来接收触发器。 Probably what you'll end up doing is starting up at device boot, to schedule some stuff. 您可能最终要做的是在设备启动时启动,以安排一些工作。 This answer here should get you into the right direction 这里的答案应该可以引导您正确的方向

After that, the best way to notify the user is with notifications (or Toast messages if you're a great fan;)) Have a look at Status Bar Notifications 在此之后,通知用户的最佳方法是使用通知(或烤面包的消息,如果你是一个巨大的风扇;))有一个在状态栏通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM