活动从在活动堆栈顶部打开的通知开始 [英] Activity started from notification opened on top of the activity stack

查看:20
本文介绍了活动从在活动堆栈顶部打开的通知开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个活动的应用程序.在其中一个上,我设置了闹钟.我按下主页按钮.触发警报时,会出现通知.单击通知时,我会启动一个类似对话的活动 (@android:style/Theme.Dialog).虽然我在桌面屏幕上,但 Android 会打开我的最后一个活动,然后在其上显示我的类似对话的活动.我只想在用户所在的任何地方显示我的对话活动.

I have an application with multiple activities. On one of them, I set up an alarm. I press the HOME button. When the alarm is triggered, a notification appears. When clicking on the notification, I start a dialogue-like Activity (@android:style/Theme.Dialog). Although I am on the desktop screen, Android opens my last activity and then shows my dialogue-like activity on top of that. I just want to show my dialogue activity wherever the user is.

有人知道出了什么问题吗?

Does anyone have an idea of what is wrong?

Intent notificationIntent = new Intent(this, NotificationActivity.class);
notificationIntent.putExtra(Constants.EXTRA_ALERT_MESSAGE, contentText);
PendingIntent contentIntent = PendingIntent.getActivity(this, Constants.PENDING_INTENT_REQ_DIALOG, notificationIntent, 0);
no.contentIntent = contentIntent;

推荐答案

您可能想要设置 android:taskAffinityandroid:launchMode="singleTask" 在您的对话框活动的清单文件中.设置 taskAffinity 将导致 Activity 在具有自己堆栈的单独任务中启动.singleTask 可能完全适合您的应用程序,也可能不完全适合您的应用程序,但您可能需要它或 singleInstance,具体取决于您的用例.您需要阅读文档以确定哪一个适合您.

You probably want to set android:taskAffinity and android:launchMode="singleTask" in your manifest file for your dialog activity. Setting taskAffinity will cause that Activity to launch in a separate task with its own stack. The singleTask may or may not be completely appropriate for your application but you'll probably want either it or singleInstance depending on your use case. You will need to read the documentation to determine which one will work for you.

这篇关于活动从在活动堆栈顶部打开的通知开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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