Android Socket programming note points

Source: Internet
Author: User

1, the operation of the socket is placed in a non-UI thread

?? In Android apps, in order to ensure the user experience of the app, you must respond as quickly as possible to the user's actions, so it is not recommended to put time-consuming actions on the UI thread in previous versions of Android. To the later version of Android3.0, there is a further restriction that the UI is not allowed in the non-UI thread, and it is forbidden to do long-response operations in the UI thread, such as networked operations.

?? The Networkonmainthread exception is thrown if the network operation is performed in the UI thread, so the socket operation must be placed within the child thread

2, to maintain the uniqueness of the Socekt instance (it is advisable to create it in singleton mode)

3. Open Internet access

<uses-permission android:name="Android.permission.INTERNET"/>

4. You can use the socket frame (Mina frame)

Android Socket programming note points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.