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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -