logo

Android - Trouble Shooting

Last Updated: 2021-11-19

android.os.NetworkOnMainThreadException

Network operations (e.g. talking to your server) must run in a separate thread from the main UI thread. That thread will run in background to minimize freezing and crashing.

Solutions:

  • put the logic in a Runnable
  • use AyncTask (deprecated in API level R)
  • use RxJava
  • use Kotlin coroutines