开发者

Alert Dialog outside of an App (not in an Activity)

开发者 https://www.devze.com 2023-03-08 07:52 出处:网络
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 Notifi

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号