I'm sending a sticky broadcast from my service, and I receive it in one of my activities. I use the following code to send the broadcast:
Intent i = new Intent();
i.setAction("presence");
i.putExtra("name",xmlContactName);
i.putExtra("fullname", xmlContactName.split("@")[0]);
i.putExtra("presence", presence);
sendStickyBroadcast(i);
I use this code to receive the broadcast in my activity:
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equalsIgnoreCase("presence")){
Contact c = new Contact();
Bundle contact = intent.getExtras();
c.name = contact.getString("name");
c.fullName = contact.getString("fullname");
c.presence = contact.getString("presence");
removeStickyBroadcast(intent);
}
};
}
According to several posts I found this is all I need to do, and as far as I know this intent is not sent to the activity again while my app is still running. However, when I close the app and run it again, I get the broadcast in my activity even without sending it from my service. It seems as though the broadcast is still lingering somewhere and it is received again after restarting the app. So far, the only thing I found to get rid of it is to restart the phone. I also unregister the receiver in my activity's onDestroy().
Do I have to do anything to completely remove the broadcast, or is it something I have to learn to live with?