Skip to content Skip to sidebar Skip to footer

How To Hold Button Reference In Singleton Class Without Memory Leak

I have a singleton 'util' class. This class is doing a lot of operation with UI elements (with some custom button, edittext etc.), so it's quite uncomfortable to pass all of the ui

Solution 1:

or it's a very horrible and hacky solution and there is some nicer

Get rid of the singleton. Then:

  • Use inheritance, with your activities/fragments extending some base class that has your utility code

  • Or, use composition, where your activities/fragments create an instance of your class with your utility code, rather than having a single global memory-leaking instance

Post a Comment for "How To Hold Button Reference In Singleton Class Without Memory Leak"