It seems that Looper
(at least the one that is created with HandlerThread
) never gets garbage collected even if not referenced by other code. I am aware of quit()
and quitSafely()
methods, however in my application I am not sure who would be responsible for calling one of these methods.
What is the right way to shut down the Looper
in an application with multiple activities and where Handler
s created on this Looper
have lifecycle different from ones of the activities. It can't be onDestroy()
of any of the activities. If I don't shut it down and the process is not killed by OS - new Looper
may be created on next app "launch" and this one will leak. Alternatively, create once, store in a static field, never quit, let it leak once. The last one seems to be the safest and easiest to implement so far.