Reputation: 3851
when I create an android Activity I can use two approaches.
In terms of performance (loading time) which one is more efficient.
Upvotes: 0
Views: 119
Reputation: 152927
I'll assume BaseActivity means some intermediate Activity class, so the question is
YourActivity extends Activity
vs
YourActivity extends BaseActivity extends Activity
In terms of performance, the less code there is, the better. Activity subclasses are supposed to call through their parents (super.onCreate()
and so on), so adding intermediate subclasses will increase the amount of code to be loaded and run.
However, if you plan to move the code from BaseActivity
to YourActivity
to speed things up, I guess it's not worth the trouble. Computers and smartphones are fast. Developer time is expensive and should be spent doing more valuable things.
So, use BaseActivity
if it provides the functionality you need. If you think you have a performance problem, measure it in order to fix it. When you think you have fixed it, measure again.
Upvotes: 1
Reputation: 1837
Simply you have to extend Activity parent class. This is the best approach but you have to override all methods for activity in order to efficiency.
Upvotes: 0
Reputation: 3874
Well extending anything (inheritace - object orientated principles), its more than performance its design issue.You should not consider inheritance for performance ever. As per android i would suggest better not extend base class, directly extend activity class.
if your building some libraries which will common activity code, then basically write it as baseclass and extend it in your project.
Upvotes: 0