如何从服务显示一个对话框对话框

2023-09-11 20:22:50 作者:问薇

我看了真的有很多关于这个话题的帖子,然而没有什么工作对我来说(或者没有我希望的效果)。

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.

到目前为止,一切都很正常,我有通知和吐司消息。不过,我想有一个对话框,该通知对新秩序的用户。

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.

这在某种程度上可能吗?

Is this somehow possible?

感谢您, 菲利普

推荐答案

我非常,非常,强烈建议你不要这样做(它违背了Android的设计和用户界面指导原则)。通知是preferred的方式来完成你在做什么(这听起来就好像你已经完成了)。

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).

话虽这么说,如果你必须这样做,我会建议只使用一个对话为主题的活动。这样,你就不必启动一个单独的对话框。请参阅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.