Android Java: best practice for common code in overrides for all Activities -
i'm not entirely sure whether following approach or terrible one. great if more experienced add his/her 2 cents :)
i have app lots of activities. in case of them must able receive messages dynamically registered receiver (in oncreate/resume/pause....) using localbroadcastmanager , run asnyctask work , display progressdialog. code needed (receiver , asnyctask) absolutely same activities.
the messages can sent @ time 1 of services.
to created activity implements (registers , unregisters receiver in oncreate/pause/resume et.c. , contains asynctask)
all other activities should extend activity don't need worry putting code of respective oncreate/onresume/onpause methods call helper classes/methods (and forgetting so).
is approach ok? ask because once stumbled upon similar question extending activities custom class (regretfully can't find anymore) , 1 answer suggested cause massive memory leaks without explaning why.
thank much!
i've had lot of success using baseactivity class other activities in project extend from. i've yet encounter memory issues due this.
an alternative approach putting common functionality in interfaces, having activities implement these necessary. there's discussion of merits of these 2 approaches here: interface vs base class
Comments
Post a Comment