Reputation: 3481
I am confused:
Is intent.getExtras.getInt()
same as intent.getIntExtra()
?
If I start my service using START_REDELIVER_INTENT
, will the extras
be included in the intent?
I get NullPointerException
on restart of my crashed service, which I find strange....
Upvotes: 2
Views: 3321
Reputation: 16833
From Intent source code :
private Bundle mExtras;
// [...]
public int getIntExtra(String name, int defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getInt(name, defaultValue);
}
public Bundle getExtras() {
return (mExtras != null)
? new Bundle(mExtras)
: null;
}
So yes. Same thing except getExtras()
may return null.
Upvotes: 4
Reputation: 60681
They are not quite identical. As you are finding out, the first variant will cause a NPE if intent.getExtras()
returns null
. The second variant does its own null-checking, and returns the default value if the extra is not present.
I can't speculate as to why you aren't getting the expected Extras without seeing more code.
Upvotes: 1