I have a “lengthy” cleanup operation that I need to perform in onDestroy()
my Activity
. What is the best way to do this?
If I use Thread
for this, my onDestroy()
will immediately return; but what happens with the thread reference? I am looking for advice on any consequences of / gotchas / trip -wire that I need to know here, since I assume that the process will still be available even after the Activity is destroyed.
History:
I am using JmDNS in my application. When the user has finished working with my application, I want to clear the JmDNS instance. I do this using the close()
method of the JmDNS
class. However, this method takes more than 5 seconds . As a result, the user sees my Activity
on the screen for a long time after touching the "Back" key.
I have yet to find out why close()
takes so long, but at the same time, I also realized that I really don't need to wait for completion to complete successfully. All I need to do is to “start” the closure and do it with it.
source share