Cannot connect using httpconnection in android

前端 未结 1 552
耶瑟儿~
耶瑟儿~ 2021-01-19 13:11

I am using android 2.3.3, i had made an rss reader which was working great, then i integrated the code of that simple rss reader into another activity, just copy pasted it c

相关标签:
1条回答
  • 2021-01-19 13:24

    It gives networkonmainthread exception

    This means that you are doing network operations on the main thread, and that's not allowed in the Strict Mode.

    "In the main thread" usually means that you are doing it in the event handlers, like onResume, onPause, or in the onClick method of your OnClickListener. You may look at this post (Painless threading) to understand what's the problem and why this is not allowed. Generally, if you perform network operations in the main thread, it would block the processing of GUI events, and if the network operation was slow, your application would be not responsive.

    Strict Mode appeared in API level 9, so this explains that why you have problem if min SDK version is 10, and why it works with min SDK version 8.

    You should use AsyncTask or other methods to do it in the background. You may refer to 1 for this.

    0 讨论(0)
提交回复
热议问题