在Android的变更申报的意图 [英] Change notification intent in Android

查看:114
本文介绍了在Android的变更申报的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有说明,我希望可以每次去我的应用程序的特定活动的用户presses上有一个通知的服务。通常这将是最后一个用户已经表明,但并非总是如此。

I have a service that shows a notification that I wish that will be able to go to a specific activity of my app each time the user presses on it. Usually it would be the last one that the user has shown, but not always.

如果该活性之前开始,则它应该返回到它,如果没有,它应该应用程序的任务的内打开它,将它添加到活动任务。

If the activity was started before, it should return to it, and if not, it should open it inside of the app's task, adding it to the activities tasks.

此外,根据服务的逻辑,某些情况下,我想更改通知的意图,这样它会针对不同的活动。

In addition, on some cases according to the service's logic, I wish to change the notification's intent so that it will target a different activity.

我该怎么办呢?是否有可能,而无需创建一个新的通知,并驳回了previous吗?是不是也有可能,而无需创建一个新的任务或活动的一个实​​例?

How do i do that? Is it possible without creating a new notification and dismissing the previous one? Is it also possible without creating a new task or an instance of an activity?

推荐答案

没有也不可能改变的活动,一旦你发出的通知。

No it wouldn't be possible to change the Activity once you have sent the notification.

您可以开始你的任务堆栈的一个活动,是没有问题的,检查出的通知服务在这里的教程:

You can start an Activity on your task stack that is not a problem, check out the notification service in the tutorial here:

http://blog.blundell-apps.com /通知换一个用户选择的时间/

您必须设置在通知挂起的意图:

You have to set a pending intent on the notification:

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0);

        // Set the info for the view that shows in the notification panel.
        notification.setLatestEventInfo(this, title, text, contentIntent);

您可以看到挂起的意图需要一个正常的意图新意图(这一点,SecondActivity.class 所以,如果你想具体的行为(如将顶端,而不是开始一个新的活动。加入的标志,就像您通常这个意图。即<一href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT"相对=nofollow> FLAG_ACTIVITY_REORDER_TO_FRONT (类似的东西

You can see the pending intent takes a normal intent "new Intent(this, SecondActivity.class" so if you want specific behaviour (like bringing to the top instead of starting a new activity. Add the flags like you would normally to this intent. i.e. FLAG_ACTIVITY_REORDER_TO_FRONT (something like that)

这篇关于在Android的变更申报的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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