views:

61

answers:

1

Hi all,

I have started using custom intents in my application and I have come across a bit of a problem.

When I send a custom intent I register a Broadcast Receiver and I catch the intent no problem.

However problems seem to appear when I send the intent again, the Broadcast Reciever seems to register two events of the intent and so on so if the intent is sent a third time I recieve it 3 times.

This is causing major problems in my application and was wondering is it normal and there is some way I have to deal with it?

Here is my code:


To Send the Intent:

Intent i = new Intent();
i.setAction(SIP_INCOMING_CALL_CANCEL_INTENT);
sendBroadcast(i);

To receive the Intent:

sipIncomingListener = new BroadcastReceiver(){

   @Override
   public void onReceive(Context context, Intent intent) {
      String action = intent.getAction(); 

      if(CallDialogActivity.SIP_INCOMING_CALL_ANSWER_INTENT.equals(action)){
         Log.d("SIPENGINE", "CALL CONNECTED SENT FROM INITINCOMINGLISTENER()");
      }  
   };

IntentFilter filter = new IntentFilter(CallDialogActivity.SIP_INCOMING_CALL_CANCEL_INTENT);
registerReceiver(sipIncomingListener, filter);

Is there anyway to make sure the Intent is only fired once??

+2  A: 

I'm not sure, why you have this issue, but are you sure that you need a Broadcast(Receiver) to handle intents? Can you please explain, why do you do that?

Back to your problem: can you provide a simple minimalistic project? I think the issue is not in the code you provided.

WarrenFaith
hi warren, I have a call screen UI and when the user say accepts a call I fire an intent that gets recieved in the Broadcast receiver in my SIP engine code. So the SIP engine knows then to send a 200 OK. Does my approach seem ok for this or would you suggest a better method? I have found the problem in my code and its a faceplam moment, I was using the method in the wrong place and registering the receiver over and over
Donal Rafferty
Ok, in this case it makes sense. Glad you solved your problem.
WarrenFaith