android挂起意图通知问题 [英] android pending intent notification problem

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

问题描述

我的应用程序中发生闹钟事件,它会启动一个通知,然后在按下时启动一个活动.问题是,当我创建多个警报时,从通知启动的活动将获得与第一个相同的附加功能.我认为问题要么出在我放入待处理意图中的意图,要么出在待处理意图本身中.我想我可能需要在其中一个上放一面旗帜,但我不知道是哪一个.

I have a alarm thing going on in my app and it launches a notification that then when pressed launched an activity. The problem is that when I create more than one alarm then the activity launched from the notification gets the same extras as the first one. I think the problem is either with the intent i put in the pending intent or in the pending intent itself. I think I might need to put a flag on one of these but I dont know which one.

Intent showIntent =new Intent(context, notificationreceiver.class);
    showIntent.putExtra("details", alarmname);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
        showIntent, 0); 

    notification.setLatestEventInfo(context, "The event is imminent",
            alarmname, contentIntent);

以及通知的接收者

Bundle b = getIntent().getExtras();
    String eventname = b.getString("details");
    details.setText(eventname);

详细信息"额外内容与每次发生通知时相同,而不是具有不同的值.在我设置意图之前,我确信正确的值会出现在详细信息"中,因此每次按下任何通知时都会出现第一个意图的问题.我怎样才能让它启动正确的意图?希望我尽可能清楚谢谢!

The "details" extra is the same to every the next time a notification happens instead of having the different value. Until I set the intents I am sure that the correct value goes to the "details" so its a problem of getting the first intent everytime i press any notification. How can I make it to launch the correct intents? Hope I was as clear as i could Thanks!

推荐答案

问题是当我创建更多不止一个警报然后是活动从通知启动获取与第一个相同的附加功能.

The problem is that when I create more than one alarm then the activity launched from the notification gets the same extras as the first one.

正确.

我怎样才能让它启动正确的意图?

How can I make it to launch the correct intents?

这取决于您是否有两个警报同时注册.

That depends on whether you have two alarms that will be registered at once, or not.

如果没有,您可以使用FLAG_ONE_SHOT或其他 PendingIntent 标志之一让您的第二个 PendingIntent 使用较新的附加功能.

If not, you can use FLAG_ONE_SHOT or one of the other PendingIntent flags to have your second PendingIntent use the newer extras.

但是,如果您将同时注册两个警报,并且具有不同的 Intent 附加项,则需要使两个 Intent 具有更大的实质性不同,例如filterEquals() 在比较两者时返回 false.例如,您可以调用 setData()setAction() 并为每个 Intent 提供不同的值.

If, however, you will have two alarms registered at once, with different Intent extras, you will need to make the two Intents be more materially different, such that filterEquals() returns false when comparing the two. For example, you could call setData() or setAction() and provide different values for each Intent.

这篇关于android挂起意图通知问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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