Android HttpClient : NetworkOnMainThreadException

后端 未结 4 1020
离开以前
离开以前 2020-11-29 12:45

I have some code below:

protected void testConnection(String url) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new Htt         


        
4条回答
  •  温柔的废话
    2020-11-29 13:28

    On ICS and later you cannot do network operations on the UI thread anymore. Instead you are forced to create a new thread and do your networking stuff there.

    Possible tools are Android's AsyncTask and the normal Java Thread.

    A good tutorial can be found here: Android Threads, Handlers and AsyncTask - Tutorial

提交回复
热议问题