Is it safe to use Looper.getMainLooper() in WorkManager?

576 Views Asked by At

This is how I used WorkManager. As you can see, I use Handler in Worker class. Handler is now deprecated since Android 11. Now we should use Handler(Looper) and I know very little about Loopers. I wonder if it's safe to use new Handler(Looper.getMainLooper()) in Worker class, what exactly is Looper, and what types of Looper exist other then main Looper.

public class MyWorker extends Worker {

    @Override
    public Worker.WorkerResult doWork() {
       new Handler().post(new Runnable() {
            @Override
            public void run () {
            //Do Something
            }});
       return WorkerResult.SUCCESS;      
    }
}
0

There are 0 best solutions below