应用程序外的警报对话框(不在活动中)。[英] Alert Dialog outside of an App (not in an Activity)

本文是小编为大家收集整理的关于应用程序外的警报对话框(不在活动中)。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

有没有办法在应用程序之外创建某种弹出窗口,如警报对话框?这个问题的上下文是我需要在推送通知的情况下向用户显示一些内容.基本上,用户收到一些消息,即使它当前未打开,应用程序也会收到它,并且通知出现在用户的任务栏中.如果用户在他们的任务栏中打开通知,我希望弹出窗口完全独立于应用程序.

到目前为止,我找到的唯一解决方案是使用 Theme.Dialog 设置调用 Activity 创建警报对话框.这个解决方案的问题是如果应用程序已经打开,Activity 将被添加到 Activity Stack.所以我得到了不一致的行为,因为如果应用程序关闭,那么弹出窗口将按我想要的方式工作,并将显示在用户当前所在的任何应用程序中.但是,如果应用程序已经打开,但当前未处于焦点状态,然后焦点会切换到我的App,然后显示对话框.

理想情况下,我希望弹出窗口独立于应用程序显示,如果用户愿意,可以使用一个按钮将用户重定向到应用程序,或者简单地关闭通知并继续他们正在执行的任何操作.

有人有什么想法吗?

推荐答案

不,你不能.但是您可以使用 launchMode 使其成为任务中的唯一活动:

http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

<块引用>

"singleTask"和"singleInstance"模式也仅在一个方面彼此不同:"singleTask"活动允许其他活动成为其任务的一部分.它始终是其任务的根,但其他活动(必须是"标准"和"单顶"活动)可以启动到该任务中.另一方面,"singleInstance"活动不允许其他活动成为其任务的一部分.这是任务中唯一的活动.如果它启动了另一个活动,该活动将被分配给不同的任务——就好像 FLAG_ACTIVITY_NEW_TASK 在意图中一样.

本文地址:https://www.itbaoku.cn/post/102704.html

问题描述

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.

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.

Anyone have any ideas?

推荐答案

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

http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

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.