I am getting an exception (android.os.NetworkOnMainThreadException) when using
Handler handler = new Handler(Looper.getMainLooper()); handler.post(runnable);
. The runnable includes a network call (closing a socket). What is the difference between handler and an async handler? not sure if that could be handy here.
Asked
Active
Viewed 211 times
0

ngaspama
- 371
- 4
- 10
-
1You have to create a new thread with its own looper to run any code on a separate thread. – Code-Apprentice Nov 11 '21 at 20:25
-
Check out the docs: https://developer.android.com/guide/background – Code-Apprentice Nov 11 '21 at 20:27
-
Using a `Handler` to move logic onto a background thread is an extremely low-level solution. You might want to consider [other solutions](https://stackoverflow.com/q/6343166/115145). – CommonsWare Nov 11 '21 at 21:16