android,kotlin2023. 7. 19. 09:48

[kotlin]Handler deprecated 해결방법

 

his constructor is deprecated.
Implicitly choosing a Looper during Handler construction can lead to bugs where operations are silently lost (if the Handler is not expecting new tasks and quits), crashes (if a handler is sometimes created on a thread without a Looper active), or race conditions, where the thread a handler is associated with is not what the author anticipated. Instead, use an Executor or specify the Looper explicitly, using Looper#getMainLooper, {link android.view.View#getHandler}, or similar. If the implicit thread local behavior is required for compatibility, use new Handler(Looper.myLooper()) to make it clear to readers.

 

val handler = Handler(Looper.getMainLooper())
handler.postDelayed({
  		// 고고
    }
}, 100)

 

Posted by thdeodls85