0

I'm testing my Android app on Cyanogen 9.1 (Android 4.0.4) and I found a weird behavior.

My app contains a BroadcastReceiver that listens to android.net.conn.CONNECTIVITY_CHANGE. According to Android documentation, this intent is not sticky.

However, when the app starts on CM9.1, it always receive a CONNECTIVITY_CHANGE intent.

Indeed, this intent is listed by the system as sticky:

>adb shell dumpsys activity
 Sticky broadcasts:
...
 * Sticky action android.net.conn.CONNECTIVITY_CHANGE
...

On other Android versions I tested on (for instance 4.2.1 stock Android on my NX4), the intent is not sticky and not received at startup, which is the correct behavior.

Is this a bug in Cyanogenmod ROM? Is there a way when receiving a sticky intent to know that it's an old one, not resulting from an actual recent event?

Thank you

gpo
  • 3,388
  • 3
  • 31
  • 53

1 Answers1

0

Is this a bug in Cyanogenmod ROM?

You will be better served asking that on a CM support board.

Is there a way when receiving a sticky intent to know that it's an old one, not resulting from an actual recent event?

You can call registerReceiver() with a null BroadcastReceiver and an IntentFilter for your desired Intent structure (e.g., android.net.conn.CONNECTIVITY_CHANGE action). If the return value is null, the broadcast was not sticky, and hence you are behaving normally.

However, there is no good way to determine how old the sticky Intent was, unless that particular Intent happens to have some sort of timestamp extra.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the tip. However, if I register a receiver with null BroadcastReceiver for the CONNECTIVITY_CHANGE intent, it always returns an intent, never null. In other words, this trick can tell me that I'm on an OS with the bug (because the intent shouldnt be sticky), but I still cannot differentiate between an old sticky intent and a recent intent... – gpo Feb 08 '13 at 16:22