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/CraZy_LegenD Jun 02 '20
Should i use base activity?
It depends
If you want to apply locale then one base activity will help you avoiding unnecessary copy paste, you need an injected model in every other activity perhaps a lifecycle bound utils that dispose resources on destroy event etc...
But if you're to have anything else that tries to abstract one behavior but you end up just adding more and more, it's a bad abstraction and shouldn't be done or just make an abstraction for that thing, for example abstractrecyclerview fragment, it should have an abstract adapter and layout manager and also live data to be observed, it's a great abstraction rather than abstractfragment and you add a LayoutManager that every other fragment inherited for no reason.
You should ask yourself: does this help me in the long run avoiding copy paste and is it readable?