r/android_devs • u/[deleted] • Jun 01 '20
Help BaseActivity vs. ActivityLifecycleCallbacks
Hi, devs!
So... I'm starting to make an architecture from scratch in order to learn how to do it (and having one done for personal projects). At my current job I started to understand how the arch is made, and my boss always explains to me the decissions he took to make it so.
But recently I read this article, so you can guess I never heard of ActivityLifecyclesCallbacks before (the same applies to fragments). I understand both of the approaches, but I want to ask you: what would you prefer, BaseActivity and BaseFragment of ActivityLifecycleCallbacks and FragmentLifecycleCallbacks?
I'd love to read some why, because, from my point of view, having a BaseActivity and then extending to another activity to add, for example, a menu drawer or fragments navigation, or whatever, seems to be a better approach, but again, I'm really new to this world and am trying to learn also from people with more experience.
Thank you all, cheers!
1
u/naked_moose Jun 01 '20
You can read about inheritance vs composition in general if you want to know more. Both have their drawbacks and benefits, but bad inheritance is always worse than bad composition. I would avoid Base classes whenever possible because you never know when someone else didn't avoid them, and you have to use it - some libraries still use BaseFragments that you have to inherit to get required functionality. Base classes for fragments and activities are also an easy way to get even more bloated fragments and activities, and they manage to be bloated on their own