java - Can I create a single class which can be the parent for every type of Activity? -
i wish have single class of activity
classes extend. have listactivities
, activities
, mapactivities
, tabactivities
, etc in app.
i have many of these different activities in app, ~12 activities. want each of them have methods in parent class.
right now, have created 4 parent activity classes extended activity depending on type(listactivity
, activity
, mapactivity
, tabactivity
)
i creating lot of redundant code - each of 4 parent activities has identical code, in exception class activity extends.
here example may clarify problem is:
- i have
activity
:menuscreen
extendsbaselistactivity
baselistactivity
extendslistactivity
baselistactivity
contains methods , fields want activities have access toi have
activity
:homescreen
extendsbaseactivity
baseactivity
extendsactivity
baseactivity
contains same methods , fields in otherbase[<type>]activity
classes(suchbaselistactivity
)
these methods/fields copy-pasted base[<type>]activity
, , seems awfully redundant me.
can create master activity class types of activity classes can use parent? if not, stuck copy , pasting code , feeling gross/dirty it?
can create master activity class types of activity classes can use parent?
no, sorry.
if not, stuck copy , pasting code , feeling gross/dirty it?
first, not need listactivity
or tabactivity
. not need listactivity
listview
; not need tabactivity
tabhost
. knocks things down 2 base classes: activity
, mapactivity
. unfortunately, do need extend mapactivity
use mapview
.
for that, can use composition minimize redundancy. rather "methods , fields want activities have access to" being implemented on activity, implement them on other object, , have baseactivity
, basemapactivity
hold onto instance of object. still need amount of duplicate code (e.g., lifecycle methods onstop()
), more stuff can located in single class.
Comments
Post a Comment