警告对话框外的应用程序(而不是在一个Activity) [英] Alert Dialog outside of an App (not in an Activity)

查看:155
本文介绍了警告对话框外的应用程序(而不是在一个Activity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来建立某种形式的弹出窗口像一个警告对话框,一个应用程序之外?这个问题的背景是我有一个需要显示的东西给用户推送通知的事件。基本上,用户收到一些消息,该应用程序接收它,即使它不是当前打开,并通知出现在用户的任务栏。如果用户打开该通知中的任务栏,我希望有一个弹出窗口出现完全独立于应用程序。

Is there a way to create some sort of popup window like an Alert Dialog, outside of an App? The context of this question is I have a need to display something to the user in the event of a Push Notification. Basically, a user receives some message, the App receives it even if it's not currently open, and a notification appears in the user's task bar. If the user opens the notification in their task bar, I want a popup to appear completely independent from the App.

我已经发现迄今呼吁与Theme.Dialog设置创建一个警告对话框一个活动的唯一解决方案。这种解决方案的问题是,活动将被添加到活动堆栈如果应用程序是已经打开。所以我得到不一致的行为,因为如果应用程序被关闭,然后在弹出的窗口工作,我想要的,并会在任何应用程序的用户目前在显示。但是,如果应用程序已经打开,但不是当前处于焦点,那么焦点将切换到我的应用程序,然后显示对话框。

The only solution I've found so far is calling an Activity with the Theme.Dialog setting create an Alert Dialog. The problem with this solution is that the Activity will be added to the Activity Stack if the App is already open. So I get inconsistent behavior, because if the App is closed, then the popup window will work as I want, and will display in whatever app the user is currently in. However, if the App is already open, but not currently in focus, then the focus will switch to my App, and then display the dialog.

在理想情况下,我想弹出应用程序的独立显示,一个按钮将用户重定向到应用程序,如果他们选择,或者干脆关闭通知,并继续无论他们正在做的。

Ideally, I would want the popup to display independently of the app, with a button to redirect the user to the app if they choose, or to simply close the notification and continue whatever they're doing.

任何人有什么想法?

推荐答案

没有,你不能。但是你可以用launchMode发挥,使其在任务的唯一活动:

No, you can't. But you can play with the launchMode to make it the only activity in the task:

<一个href="http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html">http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

在singleTask和singleInstance模式也各不相同只在一个方面:一个singleTask活动允许的其他活动是其任务的一部分。它总是在其工作的根本,但其他活动(不一定是标准​​和singleTop的活动),可以发射到该任务。阿singleInstance活性,另一方面,允许没有其他活动是其任务的一部分。它在任务的唯一活动。如果它开始另一个活动,该活动被分配给一个不同的任务 - 仿佛FLAG_ACTIVITY_NEW_TASK是在意图。

The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

这篇关于警告对话框外的应用程序(而不是在一个Activity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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