Reputation: 4972
I am new to Android development, and somewhere I read that we shouldn't put a lot of code in onCreate()
, because when running the application it will take more time.
So if I have 10 or 20 or ... UI elements (buttons, imageviews, ...) is it safe to use findItemById
for all of them in onCreate
or just find them in a method where we are going to use them? And what's the difference between an Override method and a regular method ?
Upvotes: 2
Views: 91
Reputation: 1573
There is no harm in getting reference to your UI elements in onCreate method it wouldn't effect your performance much. Defining in onCreate is beneficial because its the first method which will get executed and thus you will have reference to your view elements from the beginning.
Overriding means redefining the methods which were already defined in the class which you have inherited other methods are regular methods.
Upvotes: 1
Reputation: 530
Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.
please check this out for onCreate and other activity lifecycle method
http://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)
Upvotes: 1