What is the basis for.Oncreate(Bundle) and what is Bundle?

Asked

Viewed 5,735 times

5

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

  • Has your doubt been clarified young? Or do you need something else?

3 answers

5

onCreate()

Being part of the Click on Activity Life, the onCreate() is the method responsible for loading layouts and other boot operations. The complete life cycle of Activity occurs between the first call on onCreate(Bundle) until the call of onDestroy(). Therefore, a Activity will execute anything "global" on onCreate() and release all resources on onDestroy(). This method maintains the state of activity before it is closed.

Bundle

According to the Portuguese translation, it means "package", which are usually used for the passage of data between the various activities (Activity) android.

Details

  • +1 a good answer.

3

The method onCreate() is one of the methods of the so-called Life cycle of the Activity.

Activity is a class that should not be instantiated directly, if only created by the system Android, in response to a Intent.
View this method as if it were the constructor of the class.
He is called when the Activity is created. The part of the code relating to its initialisation, in particular the allocation of the layout, via setContentView(), to be used by it.

The class implementation requires derived classes to implement(overrun) the method onCreate(), call its implementation in the class "mother", super.onCreate() that’s right.

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

In the context of the method onCreate() is used to retrieve the values stored in the method Onsaveinstancestate().

One Activity can at any time be destroyed and recreated, for example when there is a rotation of the device.
Before destroying the Activity, the Android calls the method OnSaveInstanceState(), passing him an argument of the kind Bundle so that it can be used to store any values, among them those that define the current state of Activity.
That one Bundle is then passed to the method onCreate(), when the Activity is recreated, giving the possibility to use the stored values to initialize it in the state it had before being destroyed.

2

onCreate() is executed when a Activity is created. It is usually the method responsible for loading layouts (XML) and other boot operations. It is only executed once during the Activity.

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

The method onCreate receives a parameter of type Bundle, he is responsible for guarding the state of Activity when it is restarted, as if it were a cache.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.