如何随时在高频实时卡上显示警报对话框? [英] How to show alert dialogs at any time on a high-frequency live card?

查看:86
本文介绍了如何随时在高频实时卡上显示警报对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Glassware,它需要能够在Glassware的使用期限内随时显示警报对话框.在 Google的GDK开发指南,这需要一个有效的Context对象.但是,我使用的是高频动态卡设计范例,因此它使用Service(而不是Activity)作为其主要类别.如果我尝试将服务作为上下文传递给警报对话框构造函数,则会得到BadTokenException.

I'm working on Glassware that needs to be able to display alert dialogs at any time during the lifespan of the Glassware. As can be seen on Google's GDK development guide, this requires a valid Context object. However, I'm using the high-frequency live card design paradigm, and thus it uses a Service (rather than an Activity) as its main class. If I try to pass the service as the context to the alert dialog constructor, I get a BadTokenException.

是否有建议的方法随时显示这种类型的Glassware的警报对话框?我已经能够从Glassware菜单成功显示它们,因为该菜单确实是具有可用上下文对象的活动,但是我还必须能够在关闭菜单时显示警报.

Is there a recommended way to show alert dialogs at any time with this type of Glassware? I have been able to show them successfully from the Glassware menu, since the menu is indeed an activity with a usable context object, but I need to be able to show alerts when the menu is closed, too.

作为记录,我已经找到了两个看起来很棘手的可能解决方案:创建一个单独的以对话为主题的活动,或者使用系统警报,如前两篇帖子中所示

For the record, I have been able to find a couple of possible solutions that seem pretty hacky: create a separate dialog-themed activity, or use a system alert, as seen in the top two posts here. I'd rather avoid these if there's a better way to do it.

修改: 到目前为止,我已经接受了给出的一个答案,但是如果有人知道这样做的更官方"方式,请发布第二个答案,我可能会接受.

I've accepted the one answer given so far, but if anyone does know of a more "official" way to do it, please post a second answer and I'll probably accept it instead.

推荐答案

创建一个扩展AlertDialog.Builder并将其用作上下文的CustomAlertDialogBu​​ilder.

Create a CustomAlertDialogBuilder that extends AlertDialog.Builder and use the service as the context.

一旦您有警报对话框,但我认为您不能避免:

Once you have your alert dialog however I don't believe you can avoid:

alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 

这篇关于如何随时在高频实时卡上显示警报对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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