Avatar ·

What to use instead of deprecated Handler() in Android/Kotlin?

Hello everyone! I'm new to Kotlin and Android development, and I've run into a problem. Previously, I used `Handler()` to perform tasks with a delay or switch to the UI thread. For example, I had code like this:\n\n```kotlin\nval handler = Handler()\nhandler.postDelayed({\n textView.text = "Updated after 2 seconds"\n}, 2000)\n```\n\nBut now Android Studio underlines `Handler()` in red and says this constructor is deprecated. I understand that I need to use something else, but I can't figure out exactly what. The documentation recommends `Looper.getMainLooper()`, but I'm not sure how to apply it correctly.\n\nMy project is simple: there's a button, and when pressed, the text in a TextView should change after 3 seconds. I want to avoid memory leaks and make the code modern. Please advise,