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

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

问题描述

我在我的应用程序一个报警的事情怎么回事,它启动的话当pssed $ P $发起了一个活动的通知。 问题是,当我创建一个以上的报警,然后从通知发布活动得到相同的演员作为第一个。我认为这个问题是任何的意图我把未决意图或未决的目的本身。我想我可能需要把国旗上的这些中的一个,但我不知道是哪一个。

 意图showIntent =新的意图(背景下,notificationreceiver.class);
    showIntent.putExtra(详细信息,alarmname);

PendingIntent contentIntent = PendingIntent.getActivity(上下文,0,
        showIntent,0);

    notification.setLatestEventInfo(背景下,本次活动是迫在眉睫,
            alarmname,contentIntent);
 

和通知的接收器

 叠B = getIntent()getExtras()。
    串eventName的= b.getString(信息);
    details.setText(eventName的);
 

详细信息额外也是一样每下一次的通知情况,而不是具有不同的价值。 直到我设置的意图我相信正确的值进入到细节,因此获得的第一个目的每次我preSS任何通知它的一个问题。 我怎样才能使它推出正确的意图? 希望我很清楚,我可以 谢谢!

解决方案
  

现在的问题是,当我创造更多   多于一个报警那么活动   推出从通知获取   同样的演员作为第一个。

正确的。

  我

如何才能让它启动   正确的意图?

这取决于你是否有将马上注册,或没有两个报警。

如果不是,您可以使用 FLAG_ONE_SHOT 或其他 PendingIntent 标志有一个你的第二个 PendingIntent 使用较新的临时演员。

但是,如果你已经注册了一次,用不同的意图其他两个报警,你将需要两个意图更重大差异,使得<一href="http://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29"><$c$c>filterEquals()返回两相比较时。例如,您可以调用使用setData()的setAction()并为每个意图。

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);

And the receiver of the notification

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.

Correct.

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.

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

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.

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

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