The handler is mainly used to send events to the Message MessageQueue. Each Handler instance is associated with one thread and this thread's message queue.
so when you send runnable with a delay and exit the action, MainThread will not be destroyed, since there are still events in MessageQueue that will be processed after the delay, so this can cause memoryLeak , since your anonymous inner class runnable contains an activity link instance .
therefore, do not forget to delete all messages in onStop () from Activity by calling
handler.removeCallbacksAndMessages(null);
this will clear all pending messages and callbacks before leaving your activity.
source share