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

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

问题描述

我有多个活动的应用程序。在其中的一个,我设置了一个报警。我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;
 

解决方案

您可能需要设置<一个href="http://developer.android.com/guide/topics/manifest/activity-element.html#aff"><$c$c>android:taskAffinity和<一href="http://developer.android.com/guide/topics/manifest/activity-element.html#lmode"><$c$c>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.

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

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