活动时间从通知开幕活动堆栈的顶部堆栈、通知、时间

2023-09-12 04:22:21 作者:超酷的男生

我有多个活动的应用程序。在其中的一个,我设置了一个报警。我preSS HOME键。当触发报警时,将出现一个通知。当通知一下,我开始对话样活性(@android:款式/ Theme.Dialog)。虽然我的桌面屏幕以及Android设备打开我的最后一个活动,然后显示在最重要的是我的对话样活性。我只是想表明我的对话活动无论用户。

有没有人有什么不好?

一个想法

 意图notificationIntent =新的意图(这一点,NotificationActivity.class);
notificationIntent.putExtra(Constants.EXTRA_ALERT_MESSAGE,contentText);
PendingIntent contentIntent = PendingIntent.getActivity(此,Constants.PENDING_INTENT_REQ_DIALOG,notificationIntent,0);
no.contentIntent = contentIntent;
 

解决方案

您可能需要设置android:taskAffinity和android:launchMode="singleTask"在清单文件的对话活动。设置 taskAffinity 将导致活动来推出其自己的堆栈一个单独的任务。该 singleTask 可能会或可能不会完全适合您的应用程序,但你可能会想要么或 singleInstance 视你的用例。您将需要阅读的文件,以确定哪一个会为你工作。

通知 河南暂停举办大型公众聚集性活动 郑州市动物园 清明上河园 马街书会等已暂停开放或取消

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;

解决方案

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.