Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Bundle object is always null on onCreate()?

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.

like image 946
André Barone Avatar asked Nov 13 '11 03:11

André Barone


People also ask

Which object is passed to onCreate () method?

The savedInstanceState is a reference to a Bundle object that is passed into the onCreate method of every Android Activity.

Why do we override onCreate?

onCreate is "Overridden" because Activity has an existing implementation that your class MainActivity is replacing with it's own implementation. you would say "implemented" if the method is only declared in an interface, but there is no implementation in a super class your are replacing.

What does onCreate method do?

onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.


1 Answers

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

This is mentioned in the Activity API documentation.

like image 148
Dave Newton Avatar answered Oct 07 '22 12:10

Dave Newton