Why does not allow network access in the main thread of a process in Android? [closed]

StackOverflow https://stackoverflow.com/questions/23608113

  •  20-07-2023
  •  | 
  •  

Domanda

can you explain why does not allow network access in the main thread of a process in Android?

If anybody can explain. Its will be helpful for me.

È stato utile?

Soluzione

Because the main thread is responsible for all the UI (user interface) operations (it is also called the UI thread). Everything related to displaying stuff in the screen is done by it. So if you occupy the main thread with long operations such as a network operation, you will experience jitter in the screen and even ANR errors (Application Not Responding). In more recent versions of Android you will not even be allowed to do that as the application throws NetworkOnMainThreadException.

Altri suggerimenti

Till Donut it is used to create multiple threads from 1.6-2.3 that you was using before but if now you are using 3.0 or above then it is used to create single threaded model by using AsyncTask otherwise you ll get the NetworkOnMainThreadException.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top