java - Singleton with context in Android -
i want create singleton class callable points in application. problem class need context operations.
i don't want have recreate singleton in every activity because way looses sense, thought creating in mainactivity, init method pass context argument. point on, singleton useable, think bad design because way mainactivity reference held , might run memory leaks.
am right here?
you right not save main activity context singleton because of memory leaks. if need constant context inside singleton, use getapplicationcontext(). can safely saved. note though context not useable gui-related functions. in rare cases need activity level context inside singleton, pass calling activity context singleton's method without saving
Comments
Post a Comment