NetworkOnMainThreadException with AsyncTask

心不动则不痛 提交于 2019-12-02 09:03:37
Raghunandan

You have this

response =  request.execute().get(3, TimeUnit.SECONDS);

Calling get() makes AsyncTask no more Asynchronous. It blocks the ui thread waiting for the response. This leads to NetworkOnMainThreadException.

Get rid of get(3, TimeUnit.SECONDS);

Just use request.execute(). You can update ui in onPostExecute. You can also use interface as a callback to the Activity.

Check the answer by blackbelt in the below link

How do I return a boolean from AsyncTask?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!