It is never safe in any language to kill a thread - you do not know what this thread can do and what state it can leave. Using the undo method with a thread that periodically checks isCanceled allows the thread to control its own security — it can only do this when it would be safe to kill itself or do the necessary cleanup.
If you really don't need to kill the thread, but just want to wait until it is finished, use join.
If you absolutely need to kill the thread, continue and use stop. Just don't expect your state to be safe or consistent after that - it really should only be done when the application / activity terminates.
source share