如何显示服务中的对话框? [英] How to display a Dialog from a Service?

查看:84
本文介绍了如何显示服务中的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实阅读了很多有关该主题的文章,但是对我没有任何作用(或者没有产生我想要的效果).

I have read really a lot of posts about this topic, however nothing works for me (or doesn't have the effect I wish).

我有一个应用程序,该应用程序在登录后启动了后台服务(Service类的实现).该服务将自己与服务器同步,如果有新订单,它将创建一个通知.

I have a an application, that after logging in starts a background Service (implementation of the Service class). This service syncs itself with a Server and if a new order comes, it creates a notification.

到目前为止,一切正常,我收到了通知和Toast消息.但是,我希望有一个对话框,通知用户有关新订单的信息.

So far, everything works great, I have the notification and the Toast message. However, I would like to have a dialog, that notifies the user about the new order.

据我了解,您可以从服务中启动活动,该服务将显示对话框.这可以工作,但是活动从当前活动堆栈的顶部开始并显示对话框.我有一个没有附加视图的活动,但是它在黑色背景上正确显示了该对话框.

As I understood, you can start an activity from within the service, which displays the dialog. This works, but the activity starts on top of the current activity stack and displays the dialog. I have an activity with no view attached and it correctly displays the dialog, however, on a black background.

我想要的是在当前活动上显示对话框,导致实际背景(正在运行的活动)消失并显示对话框.

What I want is to display the dialog on the current activity, causing the actual background(the running activity) to fade and display the dialog.

这有可能吗?

推荐答案

我强烈建议您不要这样做(这与Android设计和UI准则背道而驰).通知是完成您正在做的事情(听起来好像已经完成)的首选方法.

I highly, highly, HIGHLY recommend that you DON'T do this (it goes against Android design and UI guidelines). Notifications are the preferred way to accomplish what you are doing (which it sounds as if you have already accomplished).

话虽如此,如果您必须这样做,我建议您仅使用以Dialog为主题的活动.这样,您不必启动单独的对话框.请参阅 http://developer.android.com/guide/topics/ui/themes.html# ApplyATheme 了解如何执行此操作.

That being said, if you must do it, I would recommend just using a Dialog themed activity. That way you don't have to start up a separate dialog. Please see http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme for how to do this.

这篇关于如何显示服务中的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆