can ever the intent received by a BroadcastReceiver be null?

android, android-intent, broadcastreceiver, nullpointerexception

Solution

`onReceive` in a `BroadcastReceiver` is triggered by an `Intent` with an action that it's registered to. So without Intent being an instance of `Intent` and not null, the `onReceive` method would never get called.

That being said, strange things can happen. I haven't looked over the code that Google wrote around broadcasts, so while in it's correct usage it would never be null, having the check is a good idea, because it's coming from code you don't control.

Problem

In other words : ``` @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); // can intent==null here ? // could it ever throw a NPE ? } ``` I need to solve this once and for all so please no ifs and buts. I would check for null but I suspect that it is not needed and therefore it is clumsy and inelegant to check. I had searched in the docs but have not found anything EDIT : asked at google groups - see there for some interesting points

Original source