What is the base.OnCreate (bundle) and what is bundle?

5

I'm starting with Xamarin studio and wanted to know what this "base" class is for, this method onCreate() and what is bundle ?

    
asked by anonymous 06.10.2016 / 19:40

3 answers

5

onCreate ()

As part of the Activity LifeClick , onCreate() is the method responsible for loading the layouts and other boot operations. The complete Activity lifecycle occurs between the first call in onCreate(Bundle) to the call of onDestroy() . Therefore, an Activity will execute everything "global" in onCreate() and free all resources in onDestroy() . This method keeps the activity state before it is closed.

Bundle

According to the Portuguese translation, it means "package", which are generally used for data passing between various activities ( Activity ) of Android.

Details

06.10.2016 / 19:53
3

The method onCreate () is one of the methods called Activity Life Cycle .

Activity is a class that should not be instantiated directly, should only be created by the Android system, in response to a Intent . View this method as if it were the class constructor.
It is called when the Activity is created. In it should be placed the part of the code referring to its initialization, namely the assignment of layout , via setContentView() , to be used by it.

The implementation of the class requires that the derived classes, when implementing the method, call their implementation in the "parent" class, onCreate() is that same.

Bundle represents a set of "key / value" pairs. Lets you save values of any primitive type or implement the IParcelable interface. It is commonly used in Android to pass values between components.

In the context of the super.onCreate() method is used to retrieve the values saved in the OnSaveInstanceState () .

An Activity can at any time be destroyed and re-created, for example when there is a rotation of the device. Before destroying Activity , Android calls the onCreate() method, giving it an Bundle argument so that it can be used to save any values, including those that define the current status of Activity . This Bundle is then passed to the OnSaveInstanceState() method, when Activity is recreated, giving the possibility to use the saved values to initialize it in the state it had before it was destroyed .

    
07.10.2016 / 13:28
2

onCreate() runs when a Activity is created. This is usually the method responsible for loading layouts (XML) and other initialization operations. It is only run once during% of% of Life%.

Activity is a class used to store objects in the form of key / value. Bundle is used to pass data between Android components through class Bundle .

The Intent method receives a parameter of type onCreate , it is responsible for saving the state of Bundle when it is restarted, like a cache.

    
06.10.2016 / 22:23