从后台线程弹出对话框Android [英] PopUp dialog Android from background thread

查看:62
本文介绍了从后台线程弹出对话框Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我收到来自不同线程的消息时,我需要显示一个弹出对话框,但该对话框不应该依赖于 Activity,即它应该在屏幕焦点所在的任何地方显示该对话框.

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.

能做到吗?因为对话框是按 Activity 处理的,所以我想使用服务,但又要添加一个线程,我想避免这种情况.

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:

使用通知系统——不要使用对话框代替通知

如果您的后台服务需要通知用户,使用标准通知系统——不要使用对话或吐司来通知他们.一个对话或祝酒会立即采取专注并打断用户,采取远离他们正在做的事情:用户可能在中间在对话框的那一刻输入文本出现并可能意外地作用于对话框.用户习惯于交易有通知,可以下拉他们的通知栏方便回复您的留言.

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

这篇关于从后台线程弹出对话框Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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