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

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

问题描述

我已经阅读了很多关于这个主题的帖子,但是没有什么对我有用(或者没有我想要的效果).

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

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

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天全站免登陆