不删除/替换演员意向 [英] Intent extras not removed/replaced

查看:110
本文介绍了不删除/替换演员意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置一个按钮点击报警。

触发报警与意图。

这个意图得到一个额外的诠释传递给广播接收机。

的问题是,意图的额外获取在第一设置一次
点击按钮的,而在另一点击次数永远不会改变:

 意向意图=新意图(A.this,B.class);
intent.putExtra(WAKEUP_DURATION,wakeUpDuration);
发件人的PendingIntent = PendingIntent.getBroadcast(A.this,0,意向,0);

我试图在广播接收器中移除,但没有运气:

  intent.removeExtra(A.WAKEUP_DURATION);


解决方案

使用<一个href=\"http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT\"><$c$c>FLAG_UPDATE_CURRENT当创建你的的PendingIntent 从更新额外一个新的意图

I am setting an alarm on a button click.

The alarm is triggered with an intent.

This intent get an extra "int" to pass to the Broadcast Receiver.

The problem is that the intent's extra gets set once on the first click of the button and never changes on the other clicks:

Intent intent = new Intent(A.this, B.class);
intent.putExtra(WAKEUP_DURATION, wakeUpDuration);
PendingIntent sender = PendingIntent.getBroadcast(A.this, 0, intent, 0);

I tried removing it in the Broadcast Receiver, but no luck:

intent.removeExtra(A.WAKEUP_DURATION);

解决方案

Use FLAG_UPDATE_CURRENT when creating your PendingIntent to update the extras from a new Intent.

这篇关于不删除/替换演员意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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