What do I use now that Handler() is deprecated?

Only the parameterless constructor is deprecated, it is now preferred that you specify the Looper in the constructor via the Looper.getMainLooper() method. Use it for Java new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { // Your Code } }, 3000); Use it for Kotlin Handler(Looper.getMainLooper()).postDelayed({ // Your Code }, 3000)

This Handler class should be static or leaks might occur: IncomingHandler

If IncomingHandler class is not static, it will have a reference to your Service object. Handler objects for the same thread all share a common Looper object, which they post messages to and read from. As messages contain target Handler, as long as there are messages with target handler in the message queue, the handler … Read more