I have a "long-running" cleanup operation that I need to perform in onDestroy()
of my Activity
. What is the best way to do this?
If I use a Thread
to do this, my onDestroy()
will return immediately; but what happens to the Thread reference? I am looking for advice on any implications/gotchas/trip-wires that I need to be aware of here since I assume that the process will still be alive even after the Activity is destroyed.
Background:
I am using JmDNS in my app. When the user is done with my app, I want to clean up the JmDNS instance. I do this using the close()
method of JmDNS
class. However, this method takes more than 5 seconds to complete. As a result, the user sees my Activity
on screen for a long time after touching the Back key.
I am yet to figure out why the close()
takes that long, but in the meanwhile I also realized that I really don't need to wait for the close to complete successfully. All I need is a way to "trigger" the close and be done with it.