Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a OnCreate method in android

People also ask

What is used of onCreate () method?

onCreate(Bundle savedInstanceState) Function in Android: When an Activity first call or launched then onCreate(Bundle savedInstanceState) method is responsible to create the activity.

What happens in onCreate?

onCreate() On activity creation, the activity enters the Created state. In the onCreate() method, you perform basic application startup logic that should happen only once for the entire life of the activity.

What the activity's onCreate () method does?

onCreate(): Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one.

What is the argument for onCreate function used for?

onCreate(Bundle) is called when the activity first starts up. You can use it to perform one-time initialization such as creating the user interface. onCreate() takes one parameter that is either null or some state information previously saved by the onSaveInstanceState .


If you save the state of the application in a bundle (typically non-persistent, dynamic data in onSaveInstanceState), it can be passed back to onCreate if the activity needs to be recreated (e.g., orientation change). If the orientation changes(i.e rotating your device from landscape mode to portrait and vice versa), the activity is recreated and onCreate() method is called again, so that you don't lose this prior information. If no data was supplied, savedInstanceState is null.

For further information http://developer.android.com/guide/topics/resources/runtime-changes.html


Bundle is used to save & recover state information for your activity. In instances like orientation changes or killing of your app or any other scenario that leads to calling of onCreate() again, the savedInstanceState bundle can be used to reload the previous state information. Familiarity with this article about Activity lifecycle will help.


Since the onCreate method is overridden, the super keyword is used to call the onCreate method of the base class. I think


First super.onCreate(savedInstanceState); calls the method in the superclass and saved InstanceState of the activity if any thing damage the activity so its saved in instanceState so when reload the activity it will be the same before.