弹出的对话框的Andr​​oid从后台线程弹出、线程、对话框、后台

2023-09-12 08:05:01 作者:晚吟

我需要时,我会从不同的线程的消息中显示一个弹出式对话框,但该对话框应该是不依赖于活动也就是说,它应该显示的对话框无论屏幕焦点。

I need a popup dialog to be shown when i get a message from different thread but the dialog should be not dependent on Activity i.e, it should display the dialog wherever the screen focus is.

能不能做到?因为对话是每个活动的处理,我想用一个服务,但是这又是一个更多线程的增加,我想避免这种情况。

Can it be done? Because the dialog is handled per Activity, I thought of using a service but again it would be one more thread added and I want to avoid that.

有什么其他选择?

推荐答案

如果你想问问如何显示一个对话框,当你的活动是不是用户的手机上的集中活动,然后尝试使用通知来代替。弹出一个对话框,在不同的应用程序中断用户时,他们可以做别的事情。从Android UI准则:

If you're trying to ask how to show a dialog when your activity is not the focused activity on the user's phone then try using Notifications instead. Popping up a dialog over a different application interrupts the user when they may be doing something else. From the Android UI guidelines:

使用的通知系统 - 不   代替使用对话框   通知

Use the notification system — don't use dialog boxes in place of notifications

如果您的后台服务需要   通知用户,请使用标准   通知系统 - 不使用   对话框或吐司通知他们。一个   对话框或吐司将立即采取   聚焦和中断用户,以   专注远离他们在做什么:   用户可以在中间   输入文字的那一刻的对话框   出现,可能会意外采取行动   该对话框。用户习惯于处理   与通知,可以拉下   通知阴凉处的   方便回应你   消息。

If your background service needs to notify a user, use the standard notification system — don't use a dialog or toast to notify them. A dialog or toast would immediately take focus and interrupt the user, taking focus away from what they were doing: the user could be in the middle of typing text the moment the dialog appears and could accidentally act on the dialog. Users are used to dealing with notifications and can pull down the notification shade at their convenience to respond to your message.

一个指导创建的通知是在这里:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

A guide to create notifications is here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html