androidandroid-intentserviceextras

Is intent.getExtras.getInt() same as intent.getIntExtra()?


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....


Solution

  • 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.