Why Bundle object is always null on onCreate()?

André Barone picture André Barone · Nov 13, 2011 · Viewed 18.7k times · Source

I am trying get into Android programming, and for I am taken some examples from a book. In on of these example is requested to put the following code:

public class ExemploCicloVida extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Log.i(TAG, getClassName() + " onCreate() called on: " + icicle);

        TextView t = new TextView(this);
        t.setText("Exemplo de ciclo de vida de uma Activity.\nConsulte os logs no LogCat");
        setContentView(t);
    }
}

I wonder why Bundle object is always null on this case.

Answer

Dave Newton picture Dave Newton · Nov 13, 2011

The bundle will be null if there is no previously-saved state.

This is mentioned in the Activity API documentation.