发送新的意图广播接收器给出了从previous意图额外价值 [英] Sending new intent to broadcast receiver gives extras values from previous intent

查看:195
本文介绍了发送新的意图广播接收器给出了从previous意图额外价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我广播将由广播接收器接收的意图,如应用程序仍在运行,新的意图是通过报警服务烧制但接收机被示出previous意图值。根据文档广播接收装置,返回的onReceive()后,不再活动,所以接收器应该显示它是由报警服务触发下一个意图值,但情况并非如此,任何一个可以告诉正确的做法。

I am broadcasting a intent which will be received by a broadcast receiver, as application is still running and new intent is fired by Alarm Service but the receiver is showing the previous intent value. As per docs broadcast receiver is no longer active after returning onReceive(), so receiver should show next intent values which is fired by alarm service, but it is not happening, can any one tell correct approach.

这是从活动广播意图:

 Intent intent = new Intent(SCH_ALARM_ACTION);
    intent.setClass(getBaseContext(), SchAlarmReciever.class);
    intent.putExtra("id", maxId);
    PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(),
                0,
                intent,
                0);
   alarmManager.set(AlarmManager.RTC, gc.getTimeInMillis(), pi);

这是broadreceiver:

This is broadreceiver:

@Override
    public void onReceive(Context context, Intent data) 
                {
        // TODO Auto-generated method stub

        if(data.getAction().equals(SchedulerActivity.SCH_ALARM_ACTION)){

        int id = data.getIntExtra("id",0);
        Toast.makeText(context, "in receiver "+String.valueOf(id), Toast.LENGTH_LONG).show();
                }

在这里举杯表示由第一广播从即使第二个目的是从alarmservice发射alarmservice发送的ID(第二次警报响起)

here toast shows id which is sent by first broadcast from alarmservice even when second intent is fired from alarmservice(second time alarm goes off)

推荐答案

得到答案,必须设置标志PendingIntent.FLAG_CANCEL_CURRENT同时设定意向未决的AlarmService ...

Got answer, has to set flag PendingIntent.FLAG_CANCEL_CURRENT while setting pending intent for AlarmService...

这篇关于发送新的意图广播接收器给出了从previous意图额外价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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