Android - Trouble Shooting

Updated: 2020-12-31

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