Can Activity.getIntent() ever return null?

Yes, it can,
but only in two cases:

In activity constructor:
Intent set up in internal attach method, called from Instrumentation class:

public Activity newActivity(Class<?> clazz, Context context, 
        IBinder token, Application application, Intent intent, ActivityInfo info, 
        CharSequence title, Activity parent, String id,
        Object lastNonConfigurationInstance) throws InstantiationException, 
        IllegalAccessException {
    Activity activity = (Activity)clazz.newInstance();
    ActivityThread aThread = null;
    activity.attach(context, aThread, this, token, 0, application, intent,
            info, title, parent, id,
            (Activity.NonConfigurationInstances)lastNonConfigurationInstance,
            new Configuration(), null, null);
    return activity;
}

therefore intent is always null in constructor.

After setIntent(null):
It’s possible to change intent from outside of activity with setIntent().

In all other cases it can’t.

Leave a Comment